2014-12-01 2 views
1

Моя проблема заключается в том, что мне нужно извлечь только одно поле из массива, а затем сохранить в другом массиве.Как добавить ключевое значение многомерного массива в другой массив

коды:

$obj = json_decode($event,true); 

[данные] => массив (

[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. 
     ) 

) 

)

Я попытался извлечь резюме из массива и хранить его в другом массиве:

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

Это то, что я пытаясь достичь в конце концов:

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. 
        ) 

      ) 
    ) 

Проблема им перед им не в состоянии извлечь всю сводку из массива из моего кода я извлекаться только первый индекс массива.

Я попытался получить данные, увеличив счет, хотя он не работает.

ответ

2

Просто предназначаться соответствующие данные, которые вы хотите, то так как они имеют ту же структуру, это будет то же самое на другой:

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

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

В качестве альтернативы, если вы не хотите, новую копию, вы также можете поместить ссылку на каждую копию внутри foreach и сделать unset() по тем индексам, которые вы не хотите.

foreach($obj['data'] as &$values) { 
    unset($values['metadata']['name'], $values['metadata']['publicProfileUrl']); 
} 
+0

благодаря призраку он работал – user2818060

+0

@ user3785613 уверенного человека я рад, что это помогло – Ghost

+0

мне нужна помощь я попробовал код $ я = 0; \t \t \t \t \t \t \t \t Еогеасп ($ новый [ 'данные'] [$ я] как $ значения) \t \t \t \t \t \t \t \t { \t \t \t \t \t \t \t \t \t print_r ($ значения); \t \t \t \t \t \t \t \t \t $ я ++; \t \t \t \t \t \t \t \t} – user2818060

Смежные вопросы