Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Take A QuizChallenge yourself and boost your learning! Start the quiz now to earn credits.
Take A QuizUnlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
Take A QuizPlease log in to access this content. You will be redirected to the login page shortly.
LoginGeneral Tech Bugs & Fixes 2 years ago
Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.
You cannot use the count on the array on-going. You need to filter it first!
You can use array-filter as:
$arr = [["b" => "loc04", "c" => ["com/tag/administrator">administrator" => "com/tag/administrator">administrator"]]];
$arr[] = ["b" => "loc23", "c" => ["com/tag/administrator">administrator" => "com/tag/administrator">administrator", "publisher" => "publisher"]];
$arr[] = ["b" => "loccom/tag/1">12", "c" => ["publisher" => "publisher", "viewer" => "viewer"]];
$role = "com/tag/administrator">administrator";
$a = array_filter($arr, function ($e) use ($role) {return in_array($role, $e["c"]);});
Now $a
will contain the 2 element.
If the key as the same as the value you better use isset
(faster - O(1) instead O(n)) as:
$a = array_filter($arr, function ($e) use ($role) {return isset($e["c"][$role]);});
Then you can just loop over $a
and do:
foreach($a as $location) {
echo '';
}
Live example: 3v4l
No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.
General Tech 10 Answers
General Tech 7 Answers
General Tech 3 Answers
General Tech 9 Answers
Please log in to access this content. You will be redirected to the login page shortly.
LoginReady to take your education and career to the next level? Register today and join our growing community of learners and professionals.
manpreet
Best Answer
2 years ago
I am running a loop of an
$array
where I am only including results that have a matching user role (from Wordpress users).I have the loop:
With the
$array
composing of:However, when I try to get the count of the
$array
, it is returning the number of all the$key
, and I dont know how to narrow it down to just the ones from thein_array( $userRole, $location['c']
I have tried putting the
in_array( $userRole, $location['c']
from the loop into a variable, and then outputting that but I wasnt having any success with it other than returning the value of 1, but there being two matches for administrator