A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2009 yearPHP: Strange Array Problem - Where is my value? - page 1
User InfoPosts
PHP: Strange Array Problem - Where is my value?#1
I have an array ($form) which retreives some information from $_POST:

$form = $_POST[(game(];


Now I want to work with the values in this array, but I somehow fail.

For debugging I used these commands (in the exact same order, with no extra lines inbetween):

print_r($form);
echo (#( . $form[(System_ID(] . "#";


and as returned output I get:

Array
(
[(Title(] => Empire: Total War - Special Forces
[(Genre_ID(] => 1
[(Type(] => Spiel
[(System_ID(] => 1
)
##


Any ideas where my System_ID went? It(s there in print_r, but not in the next line for echo?!?

posted date: 2009-04-09 01:17:00


Re: PHP: Strange Array Problem - Where is my value?#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2009-04-09 01:17:01


Re: PHP: Strange Array Problem - Where is my value?#3
It works for me:<? $form[(System_ID(] = 1; print_r($form); echo (#( . $form[(System_ID(] . (#(;?>Output:% php foo.phpArray( [System_ID] => 1)#1#PHP 5.2.6, on Fedora Core 10EDIT - note that there(s a hint to the real cause here. In my code the print_r output (correctly) shows the array keys without single quotes around them. The original poster(s keys did have quotes around them in the print_r output, showing that somehow the actual key contained the quote marks.

posted date: 2009-04-09 01:24:00


Re: PHP: Strange Array Problem - Where is my value?#4
Alright, I found the solution myself (a.k.a. d(oh!)I added anothervar_dump($form);for further analysis and this is what I got:array(4) { ["(Title("]=> string(34) "Empire: Total War - Special Forces" ["(Genre_ID("]=> string(1) "1" ["(Type("]=> string(5) "Spiel" ["(System_ID("]=> string(1) "1"}Notice the single quote inside the double quote?Looks as if you(re not allowed to use the single quote in html forms or they will be included in the array key:Wrong: <input type="text" name="game[(Title(]" />Correct: <input type="text" name="game[Title]" />

posted date: 2009-04-09 01:28:00


Re: PHP: Strange Array Problem - Where is my value?#5
print_r() doesn(t put quotes around keys - for debugging i(d recommend ditching print_r altogether. var_export or var_dump are better.even better: use firephp. it sends the debug info via headers, so it doesn(t mess up your output and thus is even usable with ajax. output is displayed nicely with firebug including syntax coloring for data structures. and it(s even easier to use: just fb($myvar);

posted date: 2009-04-09 01:52:00


Re: PHP: Strange Array Problem - Where is my value?#6
Ah, I wondered why your print_r output had quotes around the keys and mine didn't... :)

posted date: 2009-04-09 02:57:00


Re: PHP: Strange Array Problem - Where is my value?#7
+1 for Firephp - I didn't know about that!

posted date: 2009-04-09 02:59:00


Re: PHP: Strange Array Problem - Where is my value?#8
Yapp, FirePHP is great. I'm just too lazy to include it most of the time.

posted date: 2009-04-10 04:05:00


select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.