Re: Followup: Loop non-fixed sized array
| From: | Julio Nobrega Trabalhando | Date: | Wed, 27 Mar 2002 13:30:34 +0000 |
| Subject: | Re: Followup: Loop non-fixed sized array | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-90359@lists.php.net to get a copy of this message | ||
Is there a way to make an array with only the key defined? That maybe will
help me.
$area = array('news' => array('admin'));
print_r($area) gives me:
Array ( [corporativo] => Array ( [0] => classificados ) )
The key is '0', I need key 'classificados' without a value, so I can make
this:
function MakePowers ($area, $powers)
{
foreach ($powers as $value) {
$_SESSION[$area] = $value;
}
}
But this gives me ILLEGAL OFFSET error on $_SESISON[$area];
Any help? Again? :-)
--
Julio Nobrega.
Um dia eu chego lá:
http://sourceforge.net/projects/toca
Ajudei? Salvei? Que tal um presentinho?
http://www.submarino.com.br/wishlistclient.asp?wlid=664176742884
"Julio Nobrega Trabalhando" <inerte@hotmail.com> wrote in message
news:20020327131512.95850.qmail@pb1.pair.com...
> Hi All!
>
> Here's something I am trying to do, and I don't know if it's possible. I
> have a function that must register session variables, values that come
from
> an array. But each of these values will be the value of an session array,
of
> non-fixed size.
>
> Let me explain (w and d stands for Write and Del):
>
> What I need:
> $_SESSION['news']['w'] = 1;
> $_SESSION['news']['d'] = 1;
>
> So what I am doing:
>
> $w = 1;
> $d = 1
> $powers = ($w, $d); // This array can have an undetermined number of
values
>
> function MakePowers ($area, $powers)
> {
> foreach ($powers as $value) {
> $area = $value;
> }
> }
>
> Now here comes the real problem, $area specifies where in the $_SESSION
> array I will store the power.
>
> I did $area = $_SESSION['news'] but gives me a "undefined index
> 'news".
I
> could define 'news' for each page of my application but that's not much
> function reuse :-)
>
> And $area could be, in different pages, $_SESSION['news]['admin'],
> $_SESSION['forum'], etc...
>
> That's my non-fixed sized array. I need to make a central function that
> will store in different keys of $_SESSION values that say what powers the
> user has, powers that come from the $powers array.
>
>
> ANY help? I hope I did a good job trying to explain what I am trying to
do
> :-)
>
> Many thanks for any help, sincerely!
>
> --
>
> Julio Nobrega.
>
>