Welcome Guest, Not a member yet? Register   Sign In
WHY do PHP reindex arrays and add integer indexes?
#2

ALL PHP ARRAYS are associative arrays.

So your simple single dimensional array of : 
PHP Code:
$myArray = ['apple''banana''cherry']; 

is structurally the same as: 
PHP Code:
$yourArray = [=> 'apple'=> 'banana'=> 'cherry']; 

So, if you will using foreach like this:
PHP Code:
foreach ($myArray as $index => $value)
{
    echo 
$index ' ' $value;
}

// You'll get
// 0 apple
// 1 banana
// 2 cherry 

That's simply how PHP internals work. If you ask why is that, then you need to ask the PHP maintainers themselves.
Reply


Messages In This Thread
RE: WHY do PHP reindex arrays and add integer indexes? - by paulbalandan - 12-17-2020, 08:37 AM



Theme © iAndrew 2016 - Forum software by © MyBB