Fraze Jr. Fraze Jr. - 2 months ago 10
PHP Question

Add array to array without key IDs? - PHP

I have a big array which looks like this:

array(2) {
["Final Fantasy VII"]=>
array(5) {
["rows"]=>
array(2) {
[0]=>
array(6) {
["price"]=>
string(5) "11.69"
["price_old"]=>
string(4) "4.66"
["currency"]=>
string(4) "euro"
["portal"]=>
string(0) ""
["link"]=>
string(77) "https://de.gamesplanet.com/game/final-fantasy-vii-download--1001-1?ref=gmkeys"
["shop"]=>
string(4) "9507"
}
[1]=>
array(6) {
["price"]=>
string(5) "14.99"
["price_old"]=>
...
}
}
}

["Battlefield 1"]=>
array(3) {
["rows"]=>
array(2) {
[0]=>
array(6) {
["price"]=>
...
}
[1]=>
array(6) {
["price"]=>
...
}
}
}
}


And I want to get only certain parts of this array where the name is matching my searched title. So, I use this code for that:

function createACFRepeater($title){
$repeater = array();

if(searchForGameXML($title)){

$count = count($GLOBALS["productsXML"][$title]['rows']);

for($i = 0; $i < $count; $i++){
array_push($repeater, $GLOBALS["productsXML"][$title]['rows'][$i]);
}

return $repeater;
}else{
return $repeater;
}
}


My problem now is that the the
$repeater
array looks like this:

array(2) {
[0]=>
array(6) {
["price"]=>
string(5) "19.98"
["price_old"]=>
...
}
[1]=>
array(6) {
["price"]=>
string(4) "7.99"
["price_old"]=>
...
}
}


There is a numeric key which is pointing to the array
[0] => ...
. But what I want is simply an array in a array without any associative relations...

How can I create an array which looks like this:?

array(2) {
array(6) {
["price"]=>
string(5) "19.98"
["price_old"]=>
...
}
array(6) {
["price"]=>
string(4) "7.99"
["price_old"]=>
...
}
}


Greetings and Thank You!

Answer

You will always have numeric keys. As @lubart already said: it's impossible to have an array without keys. Btw., all of the the follwing arrays are completely equal:

$array1 = array([0] => array([0] => 'hi', [1] => array([0] => '23.5')));

$array2 = array(array('hi', array('23.5')));

$array3 = [['hi', ['23.5']]];

$array4 = [ [0] => [ [0] => 'hi', [1] => [ [0] => '23.5' ] ] ];