1

I have an array which looks like this below:

Array ( [:status0] => 1 [:status1] => 2 ) 

I would want to convert it into something like this:

Array ( [:status0] => Array ( [0] => 1 [1] => 1 ) [:status1] => Array ( [0] => 2 [1] => 1 ) ) 

i want to do this with flexibility because the number of the array and names are random. I was thinking of using a for loop something like this:

foreach ($newParam as $row){
    $newArray[$row['Continent']][$row['Country']][] = $row['City'];
}

But i cant use this in my case, please help

2
  • 1
    Where do the [1] => 1 values come from? Commented Apr 18, 2019 at 4:11
  • I also need to add that for some reason... Commented Apr 18, 2019 at 4:13

1 Answer 1

1

This code should do what you want:

$newParam = Array ( ':status0' => 1, ':status1' => 2 ) ;
foreach ($newParam as $key => $value) {
    $newArray[$key] = array($value, 1);
}
print_r($newArray);

Output:

Array (
  [:status0] => Array (
    [0] => 1
    [1] => 1
  )
  [:status1] => Array (
    [0] => 2
    [1] => 1 
  )
)

Demo on 3v4l.org

Sign up to request clarification or add additional context in comments.

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.