Skip to content

Commit 5057306

Browse files
committed
Merge pull request #15 from caxy/feature-list_diffing-new
Added update for php versions that do not have array_column as a function.
2 parents 5d492a4 + 9020584 commit 5057306

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

lib/Caxy/HtmlDiff/ListDiff.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ protected function compareChildLists()
197197
break;
198198
} else {
199199
// Get all the other matces for the same $key
200-
$columns = array_column($bestMatchPercentages, $key);
200+
$columns = $this->getArrayColumn($bestMatchPercentages, $key);
201201
$thisBestMatches = array_filter(
202202
$columns,
203203
function ($v) use ($percent) {
@@ -250,6 +250,24 @@ function ($v) use ($percent) {
250250
// Save the matches.
251251
$this->textMatches = $matches;
252252
}
253+
254+
/**
255+
* This fuction is exactly like array_column. This is added for PHP versions that do not support array_column.
256+
* @param array $targetArray
257+
* @param mixed $key
258+
* @return array
259+
*/
260+
protected function getArrayColumn(array $targetArray, $key)
261+
{
262+
$data = array();
263+
foreach ($targetArray as $item) {
264+
if (array_key_exists($key, $item)) {
265+
$data[] = $item[$key];
266+
}
267+
}
268+
269+
return $data;
270+
}
253271

254272
/**
255273
* Build multidimensional array holding the contents of each list node, old and new.

0 commit comments

Comments
 (0)