Wednesday, March 16, 2022

[FIXED] Reset PHP Array Index

Issue

I have a PHP array that looks like this:

[3] => Hello
[7] => Moo
[45] => America

What PHP function makes this?

[0] => Hello
[1] => Moo
[2] => America

Solution

The array_values() function [docs] does that:

$a = array(
    3 => "Hello",
    7 => "Moo",
    45 => "America"
);
$b = array_values($a);
print_r($b);
Array
(
    [0] => Hello
    [1] => Moo
    [2] => America
)


Answered By - Jeremy

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.