Page 5 of 5

Posted: Wed Apr 11, 2007 12:28 pm
by bouncer
now it's working :)

i have one more question, if i have a $var that is an array of strings like the one down, how can i select "name" for example with this: $var['name'] , and if i use this: $var[0]['name'] the result will be the same ?

Code: Select all

array (0) { 
  ["cod"]=> 
  string(11) "jrc11" 
  ["name"]=> 
  string(11) "name" 
  ["result"]=> 
  string(0) "" 
}
thanks in advance

Posted: Wed Apr 11, 2007 12:37 pm
by feyd
It's not possible to have both of those references be the same unless for some reason you add an element that refers to the array again.. which is silly.

Posted: Wed Apr 11, 2007 12:49 pm
by bouncer
if i want to have name as my result i do $var[0]['name'] (is the correct one (for cases like this) ?) right ?

thanks in advance

Posted: Wed Apr 11, 2007 1:02 pm
by RobertGonzalez
This output:

Code: Select all

array (0) {
  ["cod"]=>
  string(11) "jrc11"
  ["name"]=>
  string(11) "name"
  ["result"]=>
  string(0) ""
}
Suggests this array structure:

Code: Select all

<?php
$array = array (
  "cod" => "jrc11",
  "name" => "name",
  "result" => ""
);
?>
This means that you should be able to reference the value of the 'name' index with $array['name'].

PS Given the size of the strings (11) it looks like they are coming out of a database field with a CHAR(11) type. You may want to take note of that, just in case later you plan to do string length comparisons.

Posted: Wed Apr 11, 2007 1:18 pm
by bouncer
thanks Everah :)