Wanted to separate some data in php

Asked

Viewed 25 times

0

<?php 
  if(isset($_GET['acao'])){?>
       <?php  $acao = $_GET['acao'];
       switch ($acao) {
       	case 'buscar':
      		 	
       		 	$dados = array( 
				 array(
	   							"video"  => 'LWzwjcgh7_A',
	   							"imagem" => 'https://i.ytimg.com/vi/LWzwjcgh7_A/mqdefault.jpg',
	   							"titulo" => 'Amado Batista Princesa',
	   							"subtitulo" => 'Dados do video',
	   						 ),
	   		); 
       		break;
       	default:
       		# code...
       		break;
       }
	   echo(json_encode($dados));
	}
 ?>

I wanted to separate this part I’ll make a loop here I’ll duplicate

 array(
                            "video"  => 'LWzwjcgh7_A',
                            "imagem" => 'https://i.ytimg.com/vi/LWzwjcgh7_A/mqdefault.jpg',
                            "titulo" => 'Amado Batista Princesa',
                            "subtitulo" => 'Dados do video',
                         ),
  • Actually this is json but I’m not seeing the array when I put echo

  • Could you improve the wording of the question? I found it vague and confusing.

1 answer

0

There’s an error right at the beginning of the code:

<?php 
  if(isset($_GET['acao'])){?>

That sign at the end ?> closes the PHP TAG, that is, what comes next will only become HTML text.

To separate the ARRAY following the logic of its code:

echo $dados['video']; //result Lwzwjcgh7_a

echo $dados['imagem']; //https://i.ytimg.com/vi/Lwzwjcgh7_a/mqdefault.jpg

echo $dados['titulo']; //Beloved Baptist Princess

echo $dados['subtitulo']; //Video data

Browser other questions tagged

You are not signed in. Login or sign up in order to post.