Lost elements in Array
Posted: Tue Jul 15, 2008 9:01 am
Hi,
I hope someone can help.
I have a list that needs to be put into an array. I have assigned the list to a variable, then turned the list into array, and then out put the array. See below:
<? $sevdata4="30,11,23,9,0,16,268,3,16,3,0,8,0,4,0,0,0,7,20,17,28,19,13,0";?>
<? $sevdata_array4 = array_unique(array_filter(explode(",", $sevdata4), "strlen"));?>
var_dump($sevdata_array4);
The out put is displayed as:
array(16) { [0]=> string(2) "30" [1]=> string(2) "11" [2]=> string(2) "23" [3]=> string(1) "9" [4]=> string(1) "0" [5]=> string(2) "16" [6]=> string(3) "268" [7]=> string(1) "3" [11]=> string(1) "8" [13]=> string(1) "4" [17]=> string(1) "7" [18]=> string(2) "20" [19]=> string(2) "17" [20]=> string(2) "28" [21]=> string(2) "19" [22]=> string(2) "13" }
The problem is only 16 elements are listed. This can be viewed more clearly if I list the element as below:
array(16) {
[0]=> string(2) "30"
[1]=> string(2) "11"
[2]=> string(2) "23"
[3]=> string(1) "9"
[4]=> string(1) "0"
5]=> string(2) "16"
[6]=> string(3) "268"
[7]=> string(1) "3"
[11]=> string(1) "8"
[13]=> string(1) "4"
[17]=> string(1) "7"
[18]=> string(2) "20"
[19]=> string(2) "17"
[20]=> string(2) "28"
[21]=> string(2) "19"
[22]=> string(2) "13"
}
As you can see elements [8],[9],[10] are missing as are elements [12] and [14], [15], [16].
It's not because they are null values (because they are not), for instance element [8] has a value of 16, and element [9] has a value of 3.
So why is this occuring? How can I fix it?
Many thanks
Lucy
I hope someone can help.
I have a list that needs to be put into an array. I have assigned the list to a variable, then turned the list into array, and then out put the array. See below:
<? $sevdata4="30,11,23,9,0,16,268,3,16,3,0,8,0,4,0,0,0,7,20,17,28,19,13,0";?>
<? $sevdata_array4 = array_unique(array_filter(explode(",", $sevdata4), "strlen"));?>
var_dump($sevdata_array4);
The out put is displayed as:
array(16) { [0]=> string(2) "30" [1]=> string(2) "11" [2]=> string(2) "23" [3]=> string(1) "9" [4]=> string(1) "0" [5]=> string(2) "16" [6]=> string(3) "268" [7]=> string(1) "3" [11]=> string(1) "8" [13]=> string(1) "4" [17]=> string(1) "7" [18]=> string(2) "20" [19]=> string(2) "17" [20]=> string(2) "28" [21]=> string(2) "19" [22]=> string(2) "13" }
The problem is only 16 elements are listed. This can be viewed more clearly if I list the element as below:
array(16) {
[0]=> string(2) "30"
[1]=> string(2) "11"
[2]=> string(2) "23"
[3]=> string(1) "9"
[4]=> string(1) "0"
5]=> string(2) "16"
[6]=> string(3) "268"
[7]=> string(1) "3"
[11]=> string(1) "8"
[13]=> string(1) "4"
[17]=> string(1) "7"
[18]=> string(2) "20"
[19]=> string(2) "17"
[20]=> string(2) "28"
[21]=> string(2) "19"
[22]=> string(2) "13"
}
As you can see elements [8],[9],[10] are missing as are elements [12] and [14], [15], [16].
It's not because they are null values (because they are not), for instance element [8] has a value of 16, and element [9] has a value of 3.
So why is this occuring? How can I fix it?
Many thanks
Lucy