Fetch first item from the value list using (comma) limiter
I have items visually:
array(
0 => '"abc","def",ghi', //"abc","def",ghi is just value. 0----N is the expected array
1 => '"jkl", ...',
);
My actual written code in use is, so this is the concern:
开发者_StackOverflow中文版array(
'"abc","def",ghi', //"abc","def",ghi is just value. 0----N is the expected array
'"jkl", ...',
);
I want to fetch "abc", but need to ignore the rest ,"def",ghi
How would I do that with PHP?
Thanks for any pointers.
$firstitem=explode(',',$yourarray[0]);
or
explode(",", $yourarray[0], 2);//to limit the explode so the resulting array does not contain unwanted elements
$firstitem[0]
will contain the first characters of the first element from yourarray including "
$exp = explode(',', $myArray[0]);
print $exp[0];
$v = array(
0 => '"abc","def",ghi', //"abc","def",ghi is just value. 0----N is the expected array
1 => '"jkl", ...',
);
$x = reset(explode(',', $v[0]));
this is it?
精彩评论