Jump to content

Archived

This topic is now archived and is closed to further replies.

onlyican

Stupid Array Question

Recommended Posts

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

Share this post


Link to post
Share on other sites
If I understand what you're looking for, try this:
[code]<?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
?>[/code]

Ken

Share this post


Link to post
Share on other sites
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];

}

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.