简体   繁体   中英

Retrieve value from array

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM