Page 1 of 1
simple array question
Posted: Wed Oct 25, 2006 3:50 pm
by iffo
Hi, I want to make an array with only indexes no values, it is possible to do something like this
$validfields['name'];
$validfields['age'];
or will the sytax be
$validfields['name']="";
$validfields['age']="";
Posted: Wed Oct 25, 2006 4:01 pm
by feyd
Why?
It'd be the latter, more than the former.
Posted: Wed Oct 25, 2006 4:08 pm
by s.dot
or simply...
Code: Select all
$var = array('name' => '', 'age' => '');
Posted: Wed Oct 25, 2006 5:36 pm
by iffo
i have a logic where i am only interested in the indexes of the array, someone told me
$validfields['name'];
$validfields['age'];
but if i knew it was not correct, if i do print_r($validfields), it does not print anything , but on the other one
$validfields['name']="';
$validfields['age']="';
it prints.
Posted: Wed Oct 25, 2006 6:40 pm
by feyd
If you don't need the values at all, why have named indexes? Why not just place the names as values?
Posted: Wed Oct 25, 2006 6:59 pm
by Christopher
Agreed. I'm not sure conceptually what the difference between the following if you are not going to use the value in the associative one:
Code: Select all
array('name' => '', 'age' => '');
// and
array('name', 'age');