Reputation: 15
Here is my code:
<?php
$myarray = range(49500,49600);
foreach ($myarray as $key => $item) {
echo "paper_crumbs[" .$key . "] = {type: HEAD, cost: 0, is_member: false}; <br />";
}
?>
Instead of echoing:
paper_crumbs[49500] = {type: HEAD, cost: 0, is_member: false};
paper_crumbs[49501] = {type: HEAD, cost: 0, is_member: false};
...etc...
with values all the way to 49,600 as expected, it goes from 0 to 100 like:
paper_crumbs[0] = {type: HEAD, cost: 0, is_member: false};
paper_crumbs[1] = {type: HEAD, cost: 0, is_member: false};
Many thanks in advance for assistance! This is my first time posting here.
Upvotes: 0
Views: 57
Reputation: 40
Change echo "paper_crumbs[" .$key . "]
to echo "paper_crumbs[" .$item . "]
. The range is in the array values, not the keys.
Upvotes: 0
Reputation: 705
Instead of "paper_crumbs[" .$key . "] try "paper_crumbs[" .$item . "]
Upvotes: 0
Reputation: 324760
Erm... you are echoing using the keys, and expect the values to just magically show up out of nowhere?
foreach(range(49500,49600) as $i) echo "paper_crumbs[".$i."] = ...<br />";
Upvotes: 2