Extract a value from an ARRAY

dear all,
I have this piece of code inside a controller;

$ticket_data =$this->_controller->Ticket->find(‘all’, array(
‘fields’ => array(‘turno_id’),
‘conditions’ => array(‘Ticket.id’ => 53539 )));

THE PROBLEM:
I want to extract ‘turno_id’ value only and place it into a variable $ticket_turno

THE RESULTS:
tried everything, all I could do is print out the results through the following code;

echo debug($ticket_data);
echo “
”;
var_dump(current($ticket_data));
echo “
”;
echo json_encode($ticket_data,true);
echo “
”;
echo print_r($ticket_data, true);
echo “
”;

And it outputs this:

array(
(int) 0 => array(
‘Ticket’ => array(
‘turno_id’ => ‘2265’
)
)
)

array(1) { [“Ticket”]=> array(1) { [“turno_id”]=> string(4) “2265” } }
[{“Ticket”:{“turno_id”:“2265”}}]
Array ( [0] => Array ( [Ticket] => Array ( [turno_id] => 2265 ) ) )

QUESTION:
how can I isolate inside a variable the turno_id value 2265?

many thanks!
Jordi.

Everything besides searching the internet?

A big part of being a good programmer is solving problems by yourself. Something so basic you should be able to figure out yourself with some fairly simple google searches.

Dear ZooKeeper,
I keep trying, I have been for the past 2 days implementing different solutions to the problem I have.
To you it is simple, to me it is a mystery.
What I do not lack is the power of will to keep trying, but I am writing here because I need to solve the problem as soon as possible.

By the way, you made me very happy by saying this is so simple. I thought I had to leave it with no solution whatsoever.

Thanks for your input

Jordi.

what I do is mainly, trying to add the key turno_id to a text variable:

$text = $ticket_data('turno_id);

but always get errors of “string to array conversion”, “index of not blablabla”, or others.
I have written the above sentence of code in more than 100 ways during the past 2 days, and always get an error.

Please bear in mind that before I got to this particular problem, I had to solve many other simple particular problems in my cakephp app. So I am putting in a lot of effort.

thanks,
Jordi.

:smile: :smile: :smile: :smile: :smile:

UNBELIEVABLE!!!
I got it! You made me so upset that my brain has worked it out, somehow I need to be thankful to your input…and your link obviously, I hate being bossed around

the solution is:
echo $ticket_data[0][ ‘Ticket’][‘turno_id’];

my mistake was the way I ordered the elements and the syntax, too many permutations to be lucky, but then, I understood that the debugger was complaining about the index of, becuase I was not placing it in FRONT of the logic of the elements that lead to the tree leave I was trying to point to.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.