PHP Fatal error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

bouncer
Forum Contributor
Posts: 162
Joined: Wed Feb 28, 2007 10:31 am

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
bouncer
Forum Contributor
Posts: 162
Joined: Wed Feb 28, 2007 10:31 am

Post 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
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
bouncer
Forum Contributor
Posts: 162
Joined: Wed Feb 28, 2007 10:31 am

Post by bouncer »

thanks Everah :)
Post Reply