How to return more than one property with JSON?

0

I would like to know how I return more than one property in PHP. Below is the code where I return the user name and wanted to return, in addition, his registration. I tried to do the same thing just by adding the 'enrollment', but it did not work.

<?php
include('connect.php');
session_start();
if($_SESSION['logado']) {
    $nome = $_SESSION['nome'];
    //$matricula = $_SESSION['matricula'];
} 
echo json_encode(array('nomeUsuario' => $nome));
//'matricula' => $matricula));
?>
    
asked by anonymous 14.01.2015 / 13:41

2 answers

0

As I was suggested, I took a look at the script where I started the session and realized that I was missing a line of code that delegated the registration.

if($array['login'] == $login){                
            if($array['password'] == $senha){
                $_SESSION['logado'] = true;
                $_SESSION['nome'] = $array['nome'];
                $_SESSION['login'] = $array['login'];
                $_SESSION['level'] = $array['level'];
                $_SESSION['matricula'] = $array['matricula']; //ESSA ERA A LINHA QUE FALTAVA
                ...
                ...
            }
}
    
15.01.2015 / 11:50
1

Just add the data to the array, so

echo json_encode(array(
    'nomeUsuario' => $nome,
    'outro_dado' => 'novo dado'
));
    
14.01.2015 / 19:08