Forum

PHP array help need...
 
Notifications
Clear all

PHP array help needed

3 Posts
2 Users
0 Likes
202 Views
(@rusnam)
Posts: 219
Estimable Member
Topic starter
 

 

      //This is my string I want to covert to array
        $string = "&type=1&item=140";

       
$value = array_filter(explode('&', $extra));
foreach ($value as $data) {
$array[] = explode('=', $data);
}
foreach ($array as $value) {
$final[] = array($value[0] => $value[1]);
}

      var_dump($final);

Its return this

array (size=2) ----> I want to remove this top level array
  0 =>
    array (size=1)
      'type' => string '1' (length=1)
  1 =>
    array (size=1)
      'item' => string '140' (length=3)

But i want to remove the top level array.. any idea?

 
Posted : 16/04/2020 9:49 am
(@web-media)
Posts: 142
Member
 

that level neither the creator of php cannot remove. that is the variable type

$string = "&type=1&item=140&arr[]=baz";
  // Recommended
parse_str($string, $output);
print_r($output['item']);
var_dump($output['item']);
print_r($output['arr']);
var_dump($output['arr']);

var_dump($string);
 
Posted : 16/04/2020 12:19 pm
(@rusnam)
Posts: 219
Estimable Member
Topic starter
 

Is there any way to merge two arrays to get everything in single array?

 
Posted : 16/04/2020 1:26 pm
Share: