0

I am very new in PHP and I was checking whether all my controlers are in so how can I echo this? what I tried resulting nothing

 $controllers = array_intersect($json_api->get_controllers(), $active_controllers );

  $return = array(
    'json_api_version' => $version,
    'controllers' => array_values($controllers)
  );
echo $return['controllers']['controllers']; 
4
  • 2
    Show us the result/content of $json_api->get_controllers() and $active_controllers please. Also, tell us what you want as an output. Commented Feb 25, 2016 at 11:01
  • either print_r($return["controllers"]); or var_dump($return["controllers"]); (as long as you only want to PRINT these) These are even before the hello world though, you should see a php tutorial as soon as possible in order to correctly procede into your project ;) Commented Feb 25, 2016 at 11:01
  • Also, what do you mean with checking whether all my controlers are in? If it means what I think it means, you want someting like count($json_api->get_controllers()) === count($active_controllers) instead. Commented Feb 25, 2016 at 11:02
  • Array ( [0] => core [1] => ipad [2] => city ) i got this result,what i actualy need is to assign city to a variable Commented Feb 25, 2016 at 11:10

2 Answers 2

1

use print_r function:

print_r($return['controllers']);

when you want read city you do:

$arr_controllers = $return['controllers'];
$key_2 = $arr_controllers[2];

where 2 is the key

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

1 Comment

Array ( [0] => core [1] => ipad [2] => city ) i got this result,what i actualy need is to assign city to a variable
1

If you want to print the values of an array with a understandable format you should use print_r() instead of echo like so:

print_r($return['controllers']);  

You can also use var_dump() to get some extra information about the fields, like the type and lenght.

If what you need is to asign a certain index of the array to a value just do something like this:

$variable = $return['controllers'][indexOfField]; // indexOfField=2 for city field
echo $variable;

For further information about print_r() check the official manual.

2 Comments

Array ( [0] => core [1] => ipad [2] => city ) i got this result,what i actualy need is to assign city to a variable
@Melvin Ok, I have already edited it, anyway try to edit a little bit your question to make it more clear :)

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.