I'm trying to create a web panel for a client who parses information with base64 encoding. I have set up the way to decode it, and if I echo the decoded part in the loop ($data[1]), it will write the correct information. However, I need to be able to put the information into an SQL table and perform work on it before I do that. So, I'm trying to put the data into an array, but it is acting like the array is empty for some reason.
$postData has the base64 decoded information, and it was exploded using & as the exploding agent.
$tokens = array ();
for ($i = 0; count($postData) > $i; $i++) {
$data = explode("=", $postData[$i]);
$tokenAdd = array();
$tokenAdd[] = $data[1];
array_push($tokens, $tokenAdd);
}
var_dump($tokenAdd);
Are you shure you are dumping correct variable? Because $tokenAdd is rewritten on each iteration.
$tokens = array ();
for ($i = 0; count($postData) > $i; $i++) {
$data = explode("=", $postData[$i]);
// token is empty array;
$tokenAdd = array();
$tokenAdd[] = $data[1];
// push array with one string element into $tokens
array_push($tokens, $tokenAdd);
}
// dump $tokens, not $tokenAdd
var_dump($tokens);
To simplify code you may try this
$tokens = array();
foreach ($postData as $postDataItem) {
$data = explode("=", $postDataItem);
$tokens[] = array($data[1]);
}
var_dump($tokens); // array(array('containing'), array('some'), array('strings'))
or even more simple, if you are ok dealing not with array of array and with array of strings
$tokens = array();
foreach ($postData as $postDataItem) {
$data = explode("=", $postDataItem);
$tokens[] = $data[1];
}
var_dump($tokens); // array('containing', 'some', 'strings')
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments