funstad Posted January 25, 2018 Share Posted January 25, 2018 (edited) Hello, I have this array print: Array ( [0] => Array ( [name] => color [value] => red ) [1] => Array ( [name] => color [value] => blue ) [2] => Array ( [name] => color [value] => green ) [3] => Array ( [name] => age [value] => 16 ) ) I want to receive this result: Array ( [color] => Array ( [name] => color [value] => red, blue, green ) [age] => Array ( [name] => age [value] => 16 ) ) it works using the following php code: foreach ($feature_names as $row) { if (!isset($result[$row["name"]])) { $result[$row["name"]]["name"] = $row["name"]; $result[$row["name"]]["value"] = $row["value"]; } else { $result[$row["name"]]["value"] .= ", " . $row["value"]; } } How ever in PHP 7.1 using the code $result[$row["name"]]["name"] = $row["name"]; generates an error. Does someone know a work around? Thanks in advance! Edited January 25, 2018 by funstad Link to comment Share on other sites More sharing options...
justsomeguy Posted January 25, 2018 Share Posted January 25, 2018 What exactly is the error message? That format you're trying to create is redundant, do you need that specific format for something? Link to comment Share on other sites More sharing options...
iwato Posted January 27, 2018 Share Posted January 27, 2018 Will the following result satisfy you? Array ( [color] => Array ( [name] => color [value] => Array ( [0] => red [1] => blue [2] => green ) ) [age] => Array ( [name] => age [value] => 16 ) ) Roddy Link to comment Share on other sites More sharing options...
iwato Posted January 28, 2018 Share Posted January 28, 2018 If so, I will post the code that produced it. Roddy Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now