Echo in an array iteration overwrites previous echo (PHP)
Date : March 29 2020, 07:55 AM
should help you out In your code, only the third line is part of the loop. If you want to have both statements in the loop, you have to create a block: foreach ($lines as $value) {
list($title, $location) = explode("|", $value);
echo '<div id="entry"><a href="'.$location.'">'.$title.'</a></div>';
}
|
can't echo the array: only able to print it: and only echo the specific array
Date : March 29 2020, 07:55 AM
Hope this helps , This should work for you: foreach ($recorded as $rows)
array_walk($rows, function($v){
echo "<img src='" . base_url() . "upload/thumbs/" . $v->file_name . "'/>";
});
|
Echo a previously established array in php works in normal php but not in echo
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I am thinking you are not concatenating your info for $recommendedvideos. Init it before your loop: $recommendedvideos = "" and then ammend it in the loop: $recommendedvideos .= "<div class='col-md-3 col-sm-6 col-xs-6 col-ts-12 video-box'>$thumb </div> [$i]";
|
How do I echo the key or value from inside a multidimentional array without writing its key in the echo statement?
Tag : php , By : Govind Bhavan
Date : March 29 2020, 07:55 AM
I wish this help you This should work for you: Just get your associative keys into an array with array_keys(), so you can access them as a 0-based indexed array, e.g. Array
(
[0] => optionone
[1] => optiontwo
[2] => optionthree
)
<?php
$example = array(
'optionone' => array('one', 'two', 'three'),
'optiontwo' => array('a','b','c'),
'optionthree' => array(1,2,3)
);
$keys = array_keys($example);
echo $keys[0] . "<br>";
echo $example[$keys[0]][0];
?>
optionone
one
|
echo json_encoded($array) passes previous echo
Date : March 29 2020, 07:55 AM
hope this fix your issue If your Connection class does an echo and you don't want that mixed into your JSON output, you will have to control the output buffer. For example: // Start catching the output
ob_start();
// Run code that echoes unwanted stuff under the hood
$Connection = new Connection("...");
$array = $Connection->arrCol("SELECT IT FROM global", "IT");
// Clear the output buffer and stop buffering (i.e. discard that echo)
ob_end_clean();
// Output JSON
header('Content-Type: application/json');
echo json_encode($array);
|