0

I am trying to take the data that is returned to me from a json curl call, and alter the keys so I can match more precisely with a database call.

Below is the data I receive back,

Array ( [0] => Array ( [0] => Array ( [toolbar_id] => thematrix [name] => Matrix ) ) [1] => Array ( [0] => Array ( [toolbar_id] => neonlights [name] => NEON Lights ) )

The bolded area is the the key I want to change to match the value of the ['toolbar_id'];

Any help is greatly appreciated.

2 Answers 2

1

Bit of a bodge way, there may be something a little more concise, but this should do the job.

$newArr = array();
foreach ($arrReturn AS $key => $item)
{
    $newArr[$item[0]['toolbar_id']] = $item;
}
$arrReturn = $newArr;
unset($newArr);
Sign up to request clarification or add additional context in comments.

Comments

0

I'd probably write a conversion function, so something like (without tests for isset() and the like left as an exercise for the view :) ;

function convert ( $arr, $items ) {
   $ret = array () ;
   foreach ( $arr as $idx => $item )
      $ret[$items[$idx]] = $item ;
   return $ret ;
}

$new_array = convert ( $your_array_here, array ( 
   'toolbar_id', 'other_id', 'something_else' 
) ) ;

Comments

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.