1

My problem here is that I need to fetch only one field from array and then store in the another array.

Codes:

$obj = json_decode($event,true);

[data] => Array (

[0] => Array
(
    [metadata] => Array
        (
            [name] => Suchi
            [publicProfileUrl] => http://www.linkedin.com/in/cc
            [summary] => Building and scaling businesses focused on simple yet powerful consumer products has been the dream, and this has come to life both at Skype, Gumtree and now most recently at LimeRoad.com. We are the the start of the journey to build the most extensive and engaging lifestyle platform ever. Our sole objective is to make the discovery experience on LimeRoad so delightful, that we become the online destination to find gorgeous yet affordable products.Earlier, with 13m users at Gumtree, we built UK's largest horizontal classifieds business. In c. two years, we went from a No. 3 position to market leading positions in jobs and consumer-to-consumer car sales, growing visits by 35% y-o-y in the UK (marketing spend remaining unchanged). Gumtree required transformational leadership, and I spent the better part of my time there scaling team capabilities, product, sales, marketing and CS functions, whilst re-architecting the financials towards core revenue streams.Prior to this, Skype was a powerful leadership development experience - being part of the executive management team of a high growth technology company, transitioning from founder–led-startup with 3 CEO changes in 2 years, whilst also building the most dramatic upgrade of the product. What a roller coaster, but not one to trade out of!Specialties: Scaling businesses, by setting direction and managing execution around product development, marketing, sales and operations. Building and empowering high performing teams.
        )

)

[1] => Array
(
    [metadata] => Array
        (
            [name] => Suchi
            [publicProfileUrl] => http://www.linkedin.com/in/cc
            [summary] => Building and scaling businesses focused on simple yet powerful consumer products has been the dream, and this has come to life both at Skype, Gumtree and now     most recently at LimeRoad.com.  We are the the start of the journey to build the most extensive and engaging lifestyle platform ever. Our sole objective is to make the     discovery experience on LimeRoad so delightful, that we become the online destination to find gorgeous yet affordable products.Earlier, with 13m users at Gumtree, we built     UK's largest horizontal classifieds business.  In c. two years, we went from a No. 3 position to market leading positions in jobs and consumer-to-consumer car sales,     growing visits by 35% y-o-y in the UK (marketing spend remaining unchanged).  Gumtree required transformational leadership, and I spent the better part of my time there     scaling team capabilities, product, sales, marketing and CS functions, whilst re-architecting the financials towards core revenue streams.Prior to this, Skype was a     powerful leadership development experience - being part of the executive management  team of a high growth technology company, transitioning from founder–led-startup     with 3 CEO changes in 2 years, whilst also building the most dramatic upgrade of the product.   What a roller coaster, but not one to trade out of!Specialties: Scaling     businesses, by setting direction and managing execution around product development, marketing, sales and operations.  Building and empowering high performing teams.
        )

)

)

I have tried to fetch summary from array and store it in another array:

$count=0;
$newArray = array();
foreach($obj as $row)
{ 
    $newArray[] = array('summary' => $row);
    $new=$newArray[$count]['summary'][$count]['metadata']['summary'];
    $count++;
} 

This is what I'm trying to reach in the end:

    data=> Array
    (
        [0] => Array
            (
                [metadata] => Array
                    (

                        [summary] => Building and scaling businesses focused on simple yet powerful consumer products has been the dream, and this has come to life both at Skype, Gumtree and now most recently at LimeRoad.com.  We are the the start of the journey to build the most extensive and engaging lifestyle platform ever. Our sole objective is to make the discovery experience on LimeRoad so delightful, that we become the online destination to find gorgeous yet affordable products.Earlier, with 13m users at Gumtree, we built UK's largest horizontal classifieds business.  In c. two years, we went from a No. 3 position to market leading positions in jobs and consumer-to-consumer car sales, growing visits by 35% y-o-y in the UK (marketing spend remaining unchanged).  Gumtree required transformational leadership, and I spent the better part of my time there scaling team capabilities, product, sales, marketing and CS functions, whilst re-architecting the financials towards core revenue streams.Prior to this, Skype was a powerful leadership development experience - being part of the executive management  team of a high growth technology company, transitioning from founder–led-startup with 3 CEO changes in 2 years, whilst also building the most dramatic upgrade of the product.   What a roller coaster, but not one to trade out of!Specialties: Scaling businesses, by setting direction and managing execution around product development, marketing, sales and operations.  Building and empowering high performing teams.
                    )

            )
        [1] => Array
            (
                [metadata] => Array
                    (

                        [summary] => Building and scaling businesses focused on simple yet powerful consumer products has been the dream, and this has come to life both at Skype, Gumtree and now most recently at LimeRoad.com.  We are the the start of the journey to build the most extensive and engaging lifestyle platform ever. Our sole objective is to make the discovery experience on LimeRoad so delightful, that we become the online destination to find gorgeous yet affordable products.Earlier, with 13m users at Gumtree, we built UK's largest horizontal classifieds business.  In c. two years, we went from a No. 3 position to market leading positions in jobs and consumer-to-consumer car sales, growing visits by 35% y-o-y in the UK (marketing spend remaining unchanged).  Gumtree required transformational leadership, and I spent the better part of my time there scaling team capabilities, product, sales, marketing and CS functions, whilst re-architecting the financials towards core revenue streams.Prior to this, Skype was a powerful leadership development experience - being part of the executive management  team of a high growth technology company, transitioning from founder–led-startup with 3 CEO changes in 2 years, whilst also building the most dramatic upgrade of the product.   What a roller coaster, but not one to trade out of!Specialties: Scaling businesses, by setting direction and managing execution around product development, marketing, sales and operations.  Building and empowering high performing teams.
                    )

            )
    )

The problem im facing im not able fetch whole summary from array from my code i have fetched only first array index.

I have tried to fetch data by increasing count though its not working.

1 Answer 1

2

Just target the corresponding data that you want, then since they have the same structure, it'll be the same on the other one:

$new['data'] = array();
foreach($obj['data'] as $values) {
    $new['data'][]['metadata']['summary'] = $values['metadata']['summary'];
    // ^ new assignment
}

echo '<pre>';
print_r($new);

Alternatively, if you do not want a new copy, you could also put a reference on each copy inside the foreach and make an unset() on those indices that you do not want.

foreach($obj['data'] as &$values) {
    unset($values['metadata']['name'], $values['metadata']['publicProfileUrl']);
}
Sign up to request clarification or add additional context in comments.

4 Comments

i need help i have tried code $i=0; foreach($new['data'][$i] as $values) { print_r($values); $i++; }
i need to fetch Array ( [summary]=>text )Array ( [summary]=>text )
but im only able fetch first row
@user3785613 if you want to traverse the new array, its just like the original one: foreach($new['data'] as $values) { echo $values['metadata']['summary']; }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.