1
I am receiving several times in a function, when calling the function in the Controller
use the foreach
and wanted these results(times) to be printed on the screen for the user to see, but using the echo
I can’t print with just the var_dump
, but I want it to appear on the screen only hours without var_dump
.
Code of Model
:
public function select_horarios_selecionados($data, $horarios=array()){
if(is_array($horarios)){
foreach($horarios as $key){
$this->db->select('hora');
$this->db->where('dia', $data);
$this->db->where('hora', $key);
$query = $this->db->get('agendamentos')->result();
$horarios_selecionados[] = array();
if($query){
foreach($query as $value){
$horarios_selecionados[] = $value->hora;
}
}else{
return false;
}
}
return $horarios_selecionados;
}
}
Code of Controller
if($consulta = $this->agenda->select_horarios_selecionados($data, $horarios)){
foreach($consulta as $linha){
$horarios_ocup = $linha;
var_dump($horarios_ocup);
}
}else{
echo "Data e horarios diponiveis para agendamento";
}
RESULT THAT APPEARS ON THE SCREEN:
array(0) { } string(8) "09:00:00" array(0) { } string(8) "09:30:00"
I want to show only the example schedules: 09:00:00 09:30:00
uses foreach, checks in the documentation, there are examples of how to view without showing the full array, just with the formatting you want. http://php.net/manual/en/control-structures.foreach.php
– Thalles Rangel
I’m already using Foreach but it didn’t work
– sol25lua
Then check this function str_replace, but it will give you more work: http://php.net/manual/en/function.str-replace.php
– Thalles Rangel
Please I’ve seen this documentation, I need help from someone who can give me an example and a brief explanation, do not need to give the code ready.
– sol25lua
How do I use echo to see only clear hours 09:00:00 with echo without var_dump? because var_dump has array and array information
– sol25lua
The right place to give
echo
wouldn’t be the view instead of the controller? And that’s all the controller code?– bfavaretto
trial
$horarios_selecionados = array();
because here you are creating a list is not? in php you can create a list$list[]
as$list = array()
in the case as Voce did seems to me one inside the other. I honestly can not explain, because I have not tested here.– Eduardo
I’ve done this way Eduardo and it didn’t work. .
– sol25lua
What appears when you do print_r($line) ?
– Sr. André Baill