I have an array an add it in foreach loop my code is:
foreach($array as $a) {
echo var_dump($a);
}
and my output is:
how can set my output to this:

and then show count of each value in my array. how can set this?
Stony answer is good. But I realize you want to echo the length of the value that you have. So I just expanded Stony's answer.
$myarray = array();
foreach($array as $a) {
$myarray[] = $a;
}
foreach($myarray as $key => $value) {
echo "Length of $value at index $key is " . strlen($value) . " <br/> ";
}
Note that I use PHP function strlen to calcualate the length of the string. Hope this helps. Thank you.
Try this code,
$arr = array("value1", "value2", "value3", "value4");
$newArr = array();
foreach ($arr as $val) {
$newArr [] = "string '$val' (length=".strlen($val).")";
}
print_r($newArr);exit;
Expected output:
Array
(
[0] => string 'value1' (length=6)
[1] => string 'value2' (length=6)
[2] => string 'value3' (length=6)
[3] => string 'value4' (length=6)
)
var_dump($array);?