/    Sign up×
Community /Pin to ProfileBookmark

how do I get the index of an array element with a specific value?

I am working on an application that allows users to write a multichoice text online. For every question, there are 2 or more choices, out of which only one is correct and that one has an iscorrect value of 1 while others have 0. Now I am working on a form that edit the question and options at the admin end and want to search through the result of the select statement and get the position of the element “is correct” with a value of 1, how do I achieve that please? I have tried array_search() and array_keys() but still can’t get it

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJun 24.2018 — Start by doing a var_dump() or var_export() of the array you want to search, to make sure it has the expected structure. If at that point it's still not obvious what you need to do, then copy/paste the output here and tell us what the expected output is for that example data. Otherwise we're just guessing.
``php<i>
</i>// this should make it nicely formatted:
echo "&lt;pre&gt;".var_export($some_array, 1)."&lt;/pre&gt;";<i>
</i>
``
×

Success!

Help @macdanorld spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...