Multidimensional associative arrays in Bash

You can’t do what you’re trying to do: bash arrays are one-dimensional $ declare -A PERSONS $ declare -A PERSON $ PERSON[“FNAME”]=’John’ $ PERSON[“LNAME”]=’Andrew’ $ declare -p PERSON declare -A PERSON='([FNAME]=”John” [LNAME]=”Andrew” )’ $ PERSONS[1]=([FNAME]=”John” [LNAME]=”Andrew” ) bash: PERSONS[1]: cannot assign list to array member You can fake multidimensionality by composing a suitable array index … Read more

Filter rows of a 2d array by the rows in another 2d array

Two values from key => value pairs are considered equal only if (string) $elem1 === (string) $elem2 . In other words a strict check takes place so the string representations must be the same. http://php.net/manual/en/function.array-diff-assoc.php The (string) value of any array is “Array”. Thus, your call to array_diff_assoc is effectively comparing these two things: Array … Read more

How does PHP index associative arrays?

Within your user defined array you are assigning the keys manually your array means as array(1 => ‘One’,3, 2 => ‘Two’);//[1] => One [2] => 3 [2] => Two Here we have two identical index and as per DOCS its mentioned that the last overwrite the first Syntax “index => values”, separated by commas, define … Read more