0

So I looked around here for a bit but cant seem to get this right, so I am forced to make a new post. I gave it an effort! Don't hurt me.

Sample Array:

$ndata = Array
(
    [ARMOR_HEAD] => Andariel's Visage
    [ARMOR_TORSO] => Blackthorne's Surcoat
    [ARMOR_FEET] => Illusory Boots
    [ARMOR_HANDS] => Gauntlets of Akkhan
    [ARMOR_SHOULDERS] => Pauldrons of Akkhan
    [ARMOR_LEGS] => Blackthorne's Jousting Mail
    [ARMOR_BRACERS] => Nemesis Bracers
    [ARMOR_MAINHAND] => Gyrfalcon's Foote
    [ARMOR_OFFHAND] => Jekangbord
    [ARMOR_WAIST] => Blackthorne's Notched Belt
    [ARMOR_RRING] => Ring of Royal Grandeur
    [ARMOR_LRING] => Stone of Jordan
    [ARMOR_NECK] => Kymbo's Gold
)

  $count = count(preg_grep('Akkhan', $ndata));
  print_r($count);

So this is only returns 1 instead of 2. I also tried array_search(), but that simply returns a the first found with its key. Or in_array but that is just boolean I guess.. Is there a better way to go about this?

1 Answer 1

2

The first parameter to preg_grep is not a string, it is a regular expression pattern represented as a string. Try this:

preg_grep('/Akkhan/i', $ndata)

For more information, see the documentation page for preg_grep.

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

1 Comment

Thanks. Where can I find information on those patterns so I know what is going on there? Edit: Ah nice edit thanks again

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.