0

is this possible? i want to return name and type of a car, in one json element.

The normal way is this,

{
    $return = array ('label' => $row['name'],
    'Type' => $row['Type'],

    );
}
echo json_encode($return);

But i want something like this so i can just call "NameType",

$return = array ('NameType' => $row['Name', 'Type'],
    );

the above should normally be like this.

I know my syntax is wrong.

1
  • $return = array ('NameType' => array($row['Name'], $row['Type'])); ? Commented Nov 5, 2013 at 10:29

1 Answer 1

1

I don't understood well the question, but you can do

$return = array ('NameType' => $row['Name']." ".$row['Type']);

or

$return = array ('NameType' => array($row['Name'], $row['Type']));

Don't know exactly what you want to do

Sign up to request clarification or add additional context in comments.

2 Comments

yes the first one is correct, Just that it returns the values without space in between.
Then just $row['Name']." ".$row['Type'] to add space between the two. I edited my answer to fit your comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.