0
I need to know how to store data from an array in a variable, using the looping below:
Data collection:
$sql="SELECT `devicetoken` FROM `devicetokensios` ORDER BY `index`";
$resultado = mysql_query($sql) or die ("Erro .:" . mysql_error());
$deviceToken = array();
while($r = mysql_fetch_assoc($resultado))
{
$deviceToken [] = $r;
}
mysql_close();
After receiving the data, how do I go through a looping and have control of the array data using its index:
Example of how to use array data:
for($index = 0; $index <= count($deviceToken); $index ++){
$outraVarial = $deviceToken[$index];
}
Can you better explain what you want with "use this same array to print the data on the screen"? Note that
$deviceTokens
exists in your code with and without "s" at the end...– Sergio
And why do you need to pass one array to another array? Is there any real reason or you just don’t know how to use the array original*. The most modern technique for sweeping a array existing is the foreach. There inside you do what you want with each element.
– Maniero
You would like to show each position of the array or want to print the array all at once?
– Antony Alkmim
I just want to return the contents of the :D array
– Tiago Amaral
You want to return or print the
$deviceTokens
? How do you need this data from the array? What is their finality?– Antony Alkmim
I need them in string format. It will return the Devices tokens to push in the APNS. But now I’m using the implode() function and I’m getting an error saying :
Warning: implode(): Argument must be an array in
– Tiago Amaral
I found the error, I was using the <= signal in the looping, so it accessed a value above what was in the array. But I’m still worrying about the guy... I’m gonna do some checking.
– Tiago Amaral