Jump to content


Photo

Stupid Array Question


  • Please log in to reply
2 replies to this topic

#1 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 02 August 2006 - 01:13 PM

Yo

I am going brain dead I think, I swear I done this before, But I cant remember how

I have an array with multiple things in there, including items

I call these by
$item1 = $keyarray['item1'];
$item2 = $keyarray['item2'];

Now
I want to make these items into a new array
so I wont use item1 item2
I would use an array called items, and end up with a finish result, something like
Array ( [0] => prod1 [1] => prod2 )

How do I do this again?
Thanks in advance
Tell me the problem, I will try tell you the solution

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 02 August 2006 - 01:29 PM

If I understand what you're looking for, try this:
<?php
$items = array();
foreach ($keyarray as $k => $v)
     $items[] = $v;
echo '<pre>' . print_r($items,true) . '</pre>'; // just to see what's in the array
?>

Ken

#3 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 02 August 2006 - 01:37 PM

That would not work as there are loads of things in the key array
I only wanted items.
Brain clicked in

for($i = 0; $i < $num_items; $i++){
$prod = $i +1;
$item_name[$i] = $keyarray["item_name".$prod];

}
Tell me the problem, I will try tell you the solution




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users