looping through an array, wierd output
I have an array that looks like this,
Array
(
[candidate_id] => 1
[first_name] => Simon
[surname] => Ainley
[gender] => male
[talent] => presenter
[DOB] => 1987-06-12
[开发者_运维百科Location] => Huddersfield
[height] => 6' 3"
[eyes] => blue
[hair] => brown
[hair_length] => short
[accents] => Native english
[training] => none
[unions] => Actors guild
[date_created] => 2011-10-11 00:00:00
)
However when I don the following,
<?php foreach ($results as $k => $v) : ?>
<?php print_r($v); ?>
<?php endforeach; ?>
Using this I am getting output,
1 S A m p 1 H 6 b b s N n A 2
This happens when you try and echo an array element thats actually a string. eg.
$string = "hello";
echo $string[1]; // echos "e"
Make sure the structure of $results is what you think it is and you are using print_r() on the correct variable.
See also: String access and modification by character Docs.
精彩评论