-1

I have an array as below.

$as = Array(
    Array
        (
            2 => "Name: SIP/3004",
            10 => "Status: 5"
        ),

    Array
        (
            2 => "Name: SIP/3001",
            10 => "Status: 2"
        ),

    Array
        (
            2 => "Name: Local/3001@bell-cab-agent",
            10 => "Status: 1"
        )

);

I want to remove main array and I want to get sub-string from value as array key and remove current keys in all the arrays. the requested output as below

Array
        (
            "Name" => "SIP/3004",
            "Status" => "5"
        )

Array
        (
            "Name" => "SIP/3001",
            "Status" => "2"
        )

Array
        (
            "Name" => "Local/3001@bell-cab-agent",
            "Status" => "1"
        )

Thanks.

Jb31
  • 1,381
  • 1
  • 10
  • 19
ITC
  • 5
  • 1
  • 1
    You are expected to make some attempt to achieve your desired result. If you have already done so, please include the code of your attempt in the question, along with the result of that code. If you have _not_ made an attempt yet, now would be the time to do so. – Patrick Q Jul 17 '19 at 17:44
  • 1
    Hint: `array_combine` and with simple `foreach` loop should do the trick – dWinder Jul 17 '19 at 17:55
  • 1
    Possible duplicate of [For-each over an array in JavaScript?](https://stackoverflow.com/questions/9329446/for-each-over-an-array-in-javascript) – Anters Bear Jul 17 '19 at 18:03

1 Answers1

0

This should get it all in one array as you requested

$new_array = [];

foreach($as as $inner_array)
{
    $temp_array = [];
    foreach($inner_array as $val){
        $temp = explode(": ", $val);
        $temp_array[$temp[0]] = $temp[1];
    }

    array_push($new_array, $temp_array);
}

print_r($new_array);
blaiser
  • 59
  • 4