Jump to content

Array modification


tito_php

Recommended Posts

Good morning,

 

My problem is with arrays. It's very simple, but I don't understand why it doesn't work.

 

My situation is as follows. I have an array "arr_A" containing more arrays. This array "arr_A" is already initialized with values. I want to modify the position "$i" of the array "arr_A" with the array "arr_B" (which is also an array of arrays). But when I want to modify it, it stops the php execution and throws error "Maximum execution limit."

 

My code is as follows:

$arr_B = array_merge( array_slice($arr_A[$i], 0, $j)   ,     array (array ($var_1,$var_2))   ,   array_slice($arr_A[$i], $j)    );
$arr_A[$i] = $arr_B;

 

 

I've checked, and the value of "arr_B" is the one I want, and showed without problems. But when I modify the position "$i" of "arr_A" with "arr_B", it doesn't work.

 

I don't know if the problem is that "arr_B" is actually a pointer, or because I'm working with arrays of arrays, or anything else.

 

Below you will see things that I've tested and work. So maybe it can give you a clue. It's really the same as the code above, but I not pass a third parameter to the function array_merge. And that code works!!!!

 

 
$arr_B = array_merge( array_slice($arr_A[$i], 0, $j)   ,     array (array ($var_1,$var_2))   );
$arr_A[$i] = $arr_B;

 

 

Thanks for your help, this so simple and it's driving me crazy.

Link to comment
https://forums.phpfreaks.com/topic/197977-array-modification/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.