开发者

Change value in first of two arrays (multidimensional) PHP

开发者 https://www.devze.com 2023-04-09 20:27 出处:网络
I want to change the number in the first array in a multidimensional array. I have a code that outputs the value to an array and there is no chance for it to start counting from one - in my code. So m

I want to change the number in the first array in a multidimensional array. I have a code that outputs the value to an array and there is no chance for it to start counting from one - in my code. So my idea is to change the value starting from one - after it has been declared. My array look like this:

Array
(
    [53] => Array
        (
            [name] => Volkswagen
            [regularePrice] => 2139.00
        )

    [54] => Array
        (
            [name] => BMW
            [regularePrice] => 2219.00
        )

    [55] => Array
        (
            [name] => Chrysler
            [regularePrice] => 2399.00
        )
)

I want - through a while or for - go through the array and change the values 53 to 1, 54 to 2, 55 to 3 and so on depending on how long the array is.

How do 开发者_开发技巧I accomplish this?


The answer is:

array_values($arr);


did you try:

$array = array_values($array);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号