How do I make arrays, inparticular the ones that use strings instead of indexes :).
Printable View
How do I make arrays, inparticular the ones that use strings instead of indexes :).
PHP Code:Array ('index1' => 'value1', 'index2' => 'value2', 'index3' => 'value3');
How about adding to an array after it was first created, or must you clear it and make a new one for that?
Also how about Multidimensional ones :D.
P.S. that was quick :D.
The reply was even quicker ;).
There are hundreds of array functions that do just about everything you can hope for with array manipulation. You have functions like array_pop() and array_push() that let you turn it into a stack, you have merging functions, traversing functions, sorting functions, combining functions, adding functions, padding functions, callback functions ....
ok you get my drift, heres the full list.
http://uk2.php.net/manual/en/ref.array.php
Multi dimensional arrays are made by putting one array inside another.
To add a value to an array which has already been initialized, just omit the index:PHP Code:Array (Array(1,2,3,4,5), Array(3,4,5,6,7));
PHP Code:$array = Array(1,2,3,4);
$array[] = 5;
for multi dimensional:PHP Code:$main_list = array();
$main_list[0] = "Home";
$main_list[1] = "PHP";
$main_list[2] = "Links";
$main_list[3] = "Contact";
to call something from a one dimensional array use:PHP Code:$smt = array();
$smt [0] = array("one","two");
$smt [1] = array("abc","def");
$smt [2] = array("123","456");
$smt [3] = array("alpha","omega");
to call something from a multi dimensional array use:PHP Code:$main_list[0]
to see how many items in an array doPHP Code:$main_list[0][0]
edit: at least that is my neat and readable (for me) way of doing things.PHP Code:count($arrayname)