The big question of WHAT you wish to accomplish, has been asked as it is important to clarify and communicate with others the specifc plan in order to reach the intended goal.
Looking at a single array set you have these values.
array (
0 => '#rpg!!27C.html'
,1 => '01/08/2023 14:23'
,2 => 'some text1'
,3 => '/stories27C.html'
,4 => '#crowd'
)
Here:
$resultVal = $changed[$i] . "&&&" . $checked[$jj];
Your attempt to combine a $changed[$i]
array with a $checked[$jj]
gives you an "Notice: Array to string conversion ERROR"
each time the for ($i
and for ($jj
loops though. If you entered this 9
record array into each input your code would be choking 81 times on this line alone not to mention the lines dealing with $resultVal
.
The big question is WHY combine them to then turn around and explode them into separate arrays again? Does that make sense?
So WHAT do you want to do? As I understand it you wish to compare the end of KEY 0
of $changed[$i]
to the end of KEY 3
of $checked[$jj]
.
SO why not explode those values directly?
$changed[$i][0]
holds the value of your outside loop right?
$transformLValue = explode("!!",$changed[$i][0]);
Now technically THIS “exploded array” should only be defined ONCE in the for ($i
loop so it should be moved UP so it is not in the for ($jj
loop being redefined multiple times.
Then in your for ($jj
loop you will explode the $checked[$jj][3]
array on “/stories”.
$transformRValue = explode("/stories",$checked[$jj][3]);
Remember these transformValue
variables are arrays with natural KEYS 0
and 1
and as you wish to compare the end of string, which is now 2 parts so you would use KEY 1
, SO your IF condition would be written as
if($transformLValue[1] == $transformRValue[1]){
So NOW after all this we are back to that BIG question of what do you wish to accomplish?
Remember your code is looping through all the values of $changed
then for each of those sub arrays it is looping through $checked
looking for a match. I believe I got 27 matches when running your array on itself.
I went ahead and echoed $jj
to double check the values of /stories
to the $changed
value. My version
$count = count($changed);
$count2 = count($checked);
for ($i = 0; $i < $count; $i++) {
if (!empty($changed[$i]) && isset($changed[$i]) && !is_null($changed[$i]))
{
//Returns 2 part array
$transformLValue = explode("!!",$changed[$i][0]);
for ($jj =0; $jj < $count2; $jj++)
{
//Returns 2 part array
$transformRValue = explode("/stories",$checked[$jj][3]);
if($transformLValue[1] == $transformRValue[1]){
echo $jj . " : " . $transformLValue[1] . " vs " . $transformRValue[1]."<br />";
}
}
}
}
showing all the keys of matches to the 9 original records
0 : 27C.html vs 27C.html
3 : 27C.html vs 27C.html
6 : 27C.html vs 27C.html
0 : 27C.html vs 27C.html
3 : 27C.html vs 27C.html
6 : 27C.html vs 27C.html
0 : 27C.html vs 27C.html
3 : 27C.html vs 27C.html
6 : 27C.html vs 27C.html
1 : 27F.html vs 27F.html
4 : 27F.html vs 27F.html
7 : 27F.html vs 27F.html
1 : 27F.html vs 27F.html
4 : 27F.html vs 27F.html
7 : 27F.html vs 27F.html
1 : 27F.html vs 27F.html
4 : 27F.html vs 27F.html
7 : 27F.html vs 27F.html
2 : 27H.html vs 27H.html
5 : 27H.html vs 27H.html
8 : 27H.html vs 27H.html
2 : 27H.html vs 27H.html
5 : 27H.html vs 27H.html
8 : 27H.html vs 27H.html
2 : 27H.html vs 27H.html
5 : 27H.html vs 27H.html
8 : 27H.html vs 27H.html