Hello,
I have write a script with this line:
array_push($array, "$saved[0]"=>"$username");
but when I open the script in a browser an error comes:
Parse error: parse error, unexpected T_DOUBLE_ARROW in /home/www/web174/html/Toplist.php on line 14
How can I remove this error?
This line is like $array = array("1"=>"test", "2"=>"admin");...
I hope you can help me...
Sorry for my english... I'm 14 and from Germany =/
Problem with arrays
Moderator: General Moderators
not sure what your'e trying to do with this:
But array_push puts an element (or elements) at the END of an array
An example from http://www.php.net :
hope this helps
Code: Select all
array_push($array, "$savedї0]"=>"$username");An example from http://www.php.net :
Code: Select all
$stack = array ("orange", "banana");
array_push ($stack, "mango");
array_push ($stack, "apple", "raspberry");
This example would result in $stack having the following elements: Array
(
ї0] => orange
ї1] => banana
ї2] => mango
ї3] => apple
ї4] => raspberry
)hope this helps
arrays in php are a mixture between perl's arrays and hashes.
They hold key/value pairs.
If you create an array likephp assigns the key 0,1,2 to the values, but you may override this behavior, e.g.which leades to $arr['ii']=='b'.
You can append elements to an array e.g. with an empty element-selectorBut you may also add an specific element, e.g.The key of course can be contained in a variableand it can also be an array-elelemtSo, maybe you want this
They hold key/value pairs.
If you create an array like
Code: Select all
<?php $arr = array('a', 'b', 'c'); ?>Code: Select all
<?php $arr = array('i'=>'a', 'ii'=>'b', 'iii'=>'c'); ?>You can append elements to an array e.g. with an empty element-selector
Code: Select all
<?php // this will create an array that equals the first example
$arr = array('a');
$arr[] = 'b';
$arr[] = 'c';
?>Code: Select all
<?php // this will create the same array as the second example
$arr = array('i'=>'a');
$arr['ii'] = 'b';
$arr['iii'] = 'c';Code: Select all
$arr = array();
$key = 'i';
$arr[$key] = 'a';
$key .='i';
$arr[$key] = 'b';
$key .='i';
$arr[$key] = 'c'; // will also produce the second array
?>Code: Select all
<?php
$saved = array('i', 'ii', 'iii');
$arr = array();
$arr[$second[0]] = 'a';
$arr[$second[1]] = 'b';
$arr[$second[2]] = 'c'; // again the second array
?>Code: Select all
$array[$saved[0]]=$username;