KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Starting with this array $start_array = [ ["date" => "2012-05-01", "revenue" => 100], ["date" => "2012-05-02", "revenue" => 200], ]; How can I rename the keys date and revenue in the child arrays so I get this: $final_array = [ ["x" => "2012-05-01", "y" => 100], ["x" => "2012-05-02", "y" => 200], ]; Here is my attempt which works, but is messy: $final_array = array(); $max = count($start_array); for ($j = 0; $j < $max; $j++) { $final_array[] = [ 'x' => $start_array[$j]['dateid'], 'y' => $start_array[$j]['ctrl_version_revenue'], ]; }
Tags (comma-separated)
Save Edits
Cancel