February 12, 201115 yr If I have an associative arrays which is like this: ([4] => 1, [1] => 2, [3] => 1) I know that the things in the brackets is the key and the number to the right of the "arrow" is the value. How do I / what is the whole thing collectively called i.e. [4] => 1 Is it the first 'item'? If I wanted to output this as a table what do I need to do to get this "value" - if the table e.g. was something like this: Id Product Qty 1 4 2 2 1 2 3 3 1 Edited February 12, 201115 yr by Citrus Cube Design
February 12, 201115 yr $x = 0; foreach($array as $key => $value) { $x++; echo $x . ' | ' . $key . ' | ' . $value; }
February 12, 201115 yr Yes you can describe it as an item. As per the manual, there are a lot of different uses for it such as lists, stack, queue, collection So it really depends on what your use is for it, but I guess there's no wrong answer
February 14, 201115 yr $x = 0; foreach($array as $key => $value) { $x++; echo $x . ' | ' . $key . ' | ' . $value; } ...providing you're not interested in $array[0]. Alternatively, you could use: foreach($array as $key => $value) { echo $x . ' | ' . $key . ' | ' . $value; $x++; } Correct term would be an array member or a key/value pair. Edited February 14, 201115 yr by Renaissance-Design
February 14, 201115 yr That counters nothing to do with the array in my code, i just started it from 1 because his table id column started at 1.
Create an account or sign in to comment