Okay I am trying to create a boss kill log for a game that I play(Runescape). I found on the internet that the developers were gracious enough to have an api with an adventure's log that logs different activities you do in game, bossing is one of em. So I got the info into a multidimensional array structured as so:
Array
(
[magic] => 5379429
[questsstarted] => 5
[totalskill] => 2333
[questscomplete] => 134
[questsnotstarted] => 95
[totalxp] => 163169890
[ranged] => 18656921
[activities] => Array
(
[0] => Array
(
[date] => 17-Dec-2017 21:51
[details] => I killed 8 graceful followers of Armadyl, all called Kree'arra. The gods have little imagination for names.
[text] => I killed 8 Kree'arras.
etc
.
.
)
The above array isn't the whole array I shortened it to not make this too long because it is a big array. What I am trying to do is only get the values that say "I killed x boss", in this case the boss would be Kree'arra. What's got me stumped is that the string contains a number that changes, like so:
"I killed 5 kree'arras"
"I killed 3 kree'arras"
so I cant use an if statement because I would never know the exact string to use the comparison operator. I tried using array_search('I killed', array_column($runemetrics, 'text'))
, but got a blank screen. I tried a bunch of answers that I found on stackoverflow, but either I got a blank screen or it was partially what I wanted. I am thinking this is a simple solution. Here is my code:
$get_runemetrics = file_get_contents("https://apps.runescape.com/runemetrics/profile/profile?user=Thee_Newb&activities=20");
$runemetrics = json_decode($get_runemetrics, true);
if(isset($runemetrics["activities"]) === TRUE){
for($i = 0; $i < count($runemetrics["activities"]); $i++){
echo $runemetrics["activities"][$i]["text"];
}
}
EDIT: I forgot to mention that the boss changes too
答案 0 :(得分:1)
You can use strpos()
to check if text
has 'I killed'
string
for($i = 0; $i < count($runemetrics["activities"]); $i++){
$text = $runemetrics["activities"][$i]["text"];
if (strpos($text, 'I killed') > -1) {
echo $text . '<br>';
}
}