Jump to content

Recommended Posts

Hey guys,

 

I have a php array that looks like this:

Array
(
    [opportunity_items] => Array
        (
            [0] => Array
                (
                    [id] => 2783
                    [opportunity_id] => 92
                    [item_id] => 
                    [item_type] => 
                    [opportunity_item_type] => 0
                    [opportunity_item_type_name] => Group
                    [name] => Strobes
                    [transaction_type] => 
                    [transaction_type_name] => 
                    [accessory_inclusion_type] => 
                    [accessory_inclusion_type_name] => 
                    [accessory_mode] => 

The array goes on for ages, but I have only shown the bits I need. I want to create a new array that just contains the [id] key.

 

I can get the first value by doing this:

echo $array["opportunity_items"]["0"]["id"];


But I somehow I need to loop through this to get all of the rest of the values.

 

Thanks,

 

Andy

Edited by AJLX
Link to comment
https://forums.phpfreaks.com/topic/302246-php-array-help/
Share on other sites

print_r() is a debugging tool for viewing an array, it does not produce an array. This will give you the desired array.

$id_array = [];     // initialize array
foreach ($data['opportunity_items'] as $k => $item) {
    $id_array[$k] = $item['id'];
}

Link to comment
https://forums.phpfreaks.com/topic/302246-php-array-help/#findComment-1537866
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.