-1

You can easily get an key from a array but if I have the value, and I have the key,In array And wants boths, whats the best way to get it?

like :

$controller = $request->get('_controller');
$home     = array('XXX\ABCBundle\Controller\PageHomeController::indexAction'=>5, 'XXX\ABCBundle\Controller\RegistrationController::confirmedAction'=>10);

First time I want key for compression and when this is inter then want to key:-

if(in_array($controller,$home)){
       echo "blabla";
   $point = $home[$controller];

}

But this is not working.

8
  • What you're getting in $controller ? Commented Jan 21, 2014 at 6:11
  • in $controller current action . Commented Jan 21, 2014 at 6:12
  • iterate with a foreach (see stackoverflow.com/a/14706992/180100) ? Commented Jan 21, 2014 at 6:12
  • @Kunwar Siddharth Singh, @Rikesh Asked about, what is the value of the $controller ? Commented Jan 21, 2014 at 6:14
  • 1
    if (isset($home[$controller]))...? Commented Jan 21, 2014 at 6:16

1 Answer 1

1

in_array searches for a value, but you're looking for a key. You should use array_key_exists for this, or isset($home[$controller]).

if (isset($home[$controller])) {
    echo "blablah";
    $point = $home[$controller];
}
Sign up to request clarification or add additional context in comments.

Comments

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.