php - Stop parent [0] when an array stored in a variable is used in an array -


the code below outputs array in way:

screenshot

we don't want part highlighted in red, how can remove this?

<?php  $test = array();  $test2[] = array(     'key1' => '111',     'key2' => '111',     'key3' => '111', );  $test2[] = array(     'key1' => '222',     'key2' => '222',     'key3' => '222', );  $test['tax_query'] = array(     'relation' => 'and',     $test2, );  print_r($test);  ?> 

array_merge() or union operator job well, nothing tricky it.

code: (demo)

$test = array();  $test2[] = array(     'key1' => '111',     'key2' => '111',     'key3' => '111', );  $test2[] = array(     'key1' => '222',     'key2' => '222',     'key3' => '222', );  $test['tax_query']=array_merge(['relation'=>'and'],$test2);  // array_merge //$test['tax_query']=['relation'=>'and']+$test2;   // array union operator  print_r($test); 

output:

array (     [tax_query] => array         (             [relation] => ,             [0] => array                 (                     [key1] => 111                     [key2] => 111                     [key3] => 111                 )                 [1] => array                 (                     [key1] => 222                     [key2] => 222                     [key3] => 222                 )             )     ) 

Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -