Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

my full function

 function jsonData(){
            //$data = $this->DataSet->query("SELECT * FROM data_sets;");
            $data = $this->DataSet->find('all', array(
            'fields' => array('created','systolisch', 'diastolisch', 'gewicht', 'puls'),
    ));
             $columns = array();
             $values = array();

             $count = count($data);

            for($i=0; $i < $count; $i++)
               {
               $keys[] = array_values($data[$i]);
               $values [] = array_values(array_keys($data[$i]));
               }



            $array = array(
               $keys,
               $values,

                );

            return new CakeResponse(array('body' => json_encode($array), 'type' => 'json'));
    }

here is the situation:

for($i=0; $i < $count; $i++)
               {
               $keys[] = array_values($data[$i]);
               $values [] = array_values(array_keys($data[$i]));
               }

this returns:

[[[{"created":"2013-10-29 14:16:38","systolisch":"77","diastolisch":"83","gewicht":"77","puls":"77"}],[{"created":"2013-10-29 14:52:00","systolisch":"99","diastolisch":"88","gewicht":"80","puls":"100"}]],[["DataSet"],["DataSet"]]]

what i need is the keys of the results of array_values(array(keys) lile diastolisch and systolisch. the values should also be rendered as plain values and not pairs. how can i achieve this?

share|improve this question

1 Answer

You can use array_keys. This is from the php documentation:

<?php
$array = array(0 => 100, "color" => "red");
print_r(array_keys($array));

$array = array("blue", "red", "green", "blue", "blue");
print_r(array_keys($array, "blue"));

$array = array("color" => array("blue", "red", "green"),
           "size"  => array("small", "medium", "large"));
print_r(array_keys($array));
?>

This will output:

Array
(
[0] => 0
[1] => color
)

Array
(
[0] => 0
[1] => 3
[2] => 4
)
Array 
(
[0] => color
[1] => size
)
share|improve this answer
 
as you can see im already using this, without appropriate results –  thegrunt Oct 29 at 18:49
 
+1 for participating –  thegrunt Oct 29 at 18:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.