Look at the following code:
foreach($_SESSION['cart'] as $r => $stringrow) {
$rowarray=explode("#",$stringrow);
}
$_SESSION['cart'] contains the row of concatenated values the separator is "#". Which I got from the previous page (as you can see they are inserted in a session.) I am exploding $stringrow to get an array called $rowarray. Everything is fine till here. The problem is this $rowarray[] contains two array elements, each of which contain concatenated imageurls separated by "#". The concatenated image urls are in $rowarray[11] and $rowarray[12]. I am again exploding $rowarray[11] and $rowarray[12]. trying to access each imageurl. But it's not happening. till now I have used innumerable echos to see the content of the imageurl array but every time it's showing 'Array'. as the value.
To view the contents of arrays, try using either var_dump($array) or print_r($array). They'll show you the type and contents of whatever variable you feed to them. It makes debugging oddly nested arrays much easier.
Related
I have great problem because i need fiz this and i don´t know how i can do it
I have simple line of Data separated by "," and this data are differents, all data in the same line as this :
$data_1="orange";
$data_2="yellow";
$data_3="".$_POST['options']."";
$data_4="".$_POST['street']."";
$data_5="Jhon";
$data_total="".$data_1.",".$data_2.",".$data_3.",".$data_4.",".$data_5."";
How you can see all these Data go inside the same line $data_total, and easy for process using explode for get different values, my only problem it´s with values i get from $_POST when are Arrays, for example from fields as multiple select with 3 , 4 or more values send from this field
Yes i can use explode, and show results, but when for example POST it´s array of values, only get the word Array.
Try process result :
$explore=explode(",",$data_total);
$dt=0;
foreach($explore as $explores)
{
print "DATA ".$dt." - ".$explores."<br>";
/// But when loop for example number 3 only show word Array the question how show data inside Array from POST
$dt++;
}
My question it´s, how can show or extract the data from POST fields with array values, inside loop when explode line $data_total
I want get results as this for example:
orange
yellow
Result array content from $_POST['options']
Result simple content $_POST['street']
Jhon
If I understand correctly $_POST['options'] is an array and you want to save it to $data_3 to be used later but since it's an array it just prints "Array".
So you need to somehow convert array to string e.g.
$data_3 = implode(' ', $_POST['options']);
This will join all options with space between them and save it to $data_3
So i am using this PHP code to create the json output, and I am having an issue where it’s creating an array of array with the info. I would like to get rid of one array and just display the list of API’s thats been used and number that has been used.
Looks as though the difference is you have...
"apis":[{"item_search":"0\n"},{"item_recommended":"0\n"}]
and want
"apis":{"item_search":"0\n","item_recommended":"0\n"}
If this is the case, you need to change the way you build the data from just adding new objects each time to setting the key values directly in the array...
$zone_1 = [];
foreach($zone_1_apis as $api_name ) {
$zone_1[substr($api_name, 0,-5)] = file_get_contents('keys/'.$_GET['key'].'/zone_1/'.$api_name);
}
You also need to do the same for $zone_2 as well.
It may also be good to use trim() round some of the values as they also seem to contain \n characters, so perhaps...
trim(file_get_contents('keys/'.$_GET['key'].'/zone_1/'.$api_name))
While retrieving values from array without index in PHP I am getting nothing.
From my database value is stored like ["SCHOOL"] and I want to get just SCHOOL from this.
It's not treated as array instead it's treated as a string.
What will be the solution if want to treat this as array and get value of that array.
My Code is as follows :
$stream_arr = $res_tbl['streams'];
which gives result as ["SCHOOL"]
and I want just SCHOOL from this.
I am using code as $stream = $stream_arr[0];
and I get '[' this as result.
If I assign manual value to $stream_arr = ["SCHOOL"],
above code works and returns SCHOOL as expected.
But for results from my database is not working where result is same as the one I manually assigned.
To eliminate braces from the string you can use below code.
$stream_arr = '["SCHOOL"]';
$temp=explode('"',$stream_arr);
$val=$temp[1];
echo $val; //it will dispaly 'SCHOOL'.
But check the insert query(from the place you store data into db) that why it is storing with braces? if it is done by you as required then proceed else first fix that issue instead of eliminating braces in php code.
Before the cries of "DUPLICATE" begin, I've used several posts here and elsewhere as guides in trying to solve this problem and they've taken me a long way, but I'm stuck at the last step.
I have a JSON object that goes five deep. This object is used to populate a table on a webpage. Each item in the table has a score from 0-100, but they just get tossed into the table haphazardly. I want them to appear sorted with the lowest scores at the top.
What I did:
$jarr = json_decode($json, true);
$marr = $jarr['g'];
foreach ($marr as $key => $row){
$score[$key] = $row['score'];
$component[$key] = $row[$key];
}
array_multisort($score, SORT_ASC, $component, SORT_STRING, $marr);
print_r($marr);
Reasoning: the smaller object 'g' is an array of associative arrays inside the larger JSON object and is the only one that actually needs to be sorted, so I operated on only that portion and got functional code.
When I put this snippet into the source, it didn't break the page but I'm only getting the output of the scores; I need all the other information inside the lower arrays, also. I tried applying the logic to the larger JSON object, but that did nothing (could just be user error, here), and I tried sorting the smaller object and printing the larger one.
How can I return the whole JSON object with the 'g' object sorted?
Edit: I've found that part of the problem is that the source code isn't turning the JSON into an array where my code snippet is. That explains why they're not compatible, but still leaves me trying to get the sorting working.
That code does what I need it to. The last step was just to cast the resulting array as an object and make sure the Smarty code was referencing everything correctly.
I have an array of CLOB datatypes. In my sample data, there are two items in the array. The array is embedded in a FOR loop that will loop until all of the data is read from the array (in this case, twice). I have a function that reads the CLOB data into a string, then returns the string, literally just:
function getCLOB($clob)
{
$str = $clob->read($clob->size());
return $str;
}
My problem is that it reads in the first thing I send it fine and I can get that to display back in the FOR loop. However, when I send the second one, the string is empty. I put in some echos to see what was happening with the data and the $clob variable has data once it's in the function, but the $str variable is empty after the first line of the function. Does anyone have any ideas on why it works once but not the second time?