I have the following array:
$phones = array(
[0] => Apple iPhone 4
[1] => Apple iPhone 5
[2] => Samsung Galaxy S6
)
What I'd like to do is split this array up, separating the brand from the model of phone, so in the end I can build an array that would give me this:
$phone_array = array (
'Apple' => array (
'iPhone 4', 'iPhone 5'
),
'Samsung' => array (
'Galaxy S6',
)
)
So far, I have the following unfinished code:
$brand_dictionary = "/(samsung|apple|htc|sony|nokia)/i";
foreach($phones as $p) {
if(stripos($p,$brand_dictionary)) {
pr($p);
die();
}
}
But this isn't working correctly at all.