0

I combined 2 objects as below, but I don't want the keys to be in the output I get.

$link1 = '{"Success":true,"Result":[{"eventId":650810,"sportId":"2"}]}';
$link2 = '{"Success":true,"Result":[{"eventId":650811,"sportId":"2"}]}';

$a []= json_decode($link1, true);
$a []= json_decode($link2, true);

echo "<pre>";
print_r($a);

the output i get in this way is as follows, without using foreach [0] => Array,[1] => Array I don't want these to happen

Array
(
[0] => Array
    (
        [Success] => 1
        [Result] => Array
            (
                [0] => Array
                    (
                        [eventId] => 650810
                        [sportId] => 2
                    )

            )

    )

 [1] => Array
    (
        [Success] => 1
        [Result] => Array
            (
                [0] => Array
                    (
                        [eventId] => 650811
                        [sportId] => 2
                    )

            )

    )

)

Since I will search with the function, I need to remove the keys and I need to get the output as below.

Array
(
 Array
(
    [Success] => 1
    [Result] => Array
        (
            [0] => Array
                (
                    [eventId] => 650810
                    [sportId] => 2
                )

        )

)

  Array
 (
    [Success] => 1
    [Result] => Array
        (
            [0] => Array
                (
                    [eventId] => 650811
                    [sportId] => 2
                )

        )

)

)

many of my attempts have been consistently unsuccessful

ThePro
  • 31
  • 6
  • 1
    Both arrays are the same. You can try something like this `foreach($array as $index => $value){...}`. You will realize they both have the same indexes. – ruleboy21 Feb 12 '22 at 19:40
  • I need to do it without using foreach – ThePro Feb 12 '22 at 20:09
  • 1
    It's still the same. Array elements without keys are automatically indexed from 0 to the length of the array minus one. So the elements in your expected array technically have keys 0 and 1. – ruleboy21 Feb 12 '22 at 20:16
  • 1
    All array elements must have a key. You cannot build an array without key. – Anisur Rahman Feb 14 '22 at 06:36
  • ruleboy21 and AnisurRahman, Thank you for the information you have given, I understand that such a thing is not possible, thank you – ThePro Feb 14 '22 at 13:14

0 Answers0