Extract a row by value from php array - php

This is my array:
Array (
[0] => Array ( [SocketID] => 1 [SocketName] => Name [SocketDecimal] => 0 [SocketHex] => 00 [SocketAtt] => 1 [Category] => 1 [Value] => 100 [Procentage] => 0 )
[1] => Array ( [SocketID] => 2 [SocketName] => Name2 [SocketDecimal] => 50 [SocketHex] => 32 [SocketAtt] => 1 [Category] => 1 [Value] => 800 [Procentage] => 0 )
[2] => Array ( [SocketID] => 3 [SocketName] => Name3 [SocketDecimal] => 100 [SocketHex] => 64 [SocketAtt] => 1 [Category] => 1 [Value] => 60 [Procentage] => 0 )
)
How can I extract a row by SocketDecimal?
For example: I want to extract row where SocketDecimal = 50 and make new an array only with that row.

foreach($array as $entry) {
if($entry['SocketDecimal'] == 50)
$newArr[] = $entry;
}
$newArr will contain the desired "row". Of course you can manipulate the if-statement depending on which "row" (I'd just call it array entry) you want to extract.

It's not the best way for big data! It's easy for deep multiarrays.
$arr = array(
array('socket_id'=>1,'name'=>'test1'),
array('socket_id'=>2,'name'=>'test2'),
array('socket_id'=>3,'name'=>'test3'),
array('socket_id'=>2,'name'=>'test4')
);
$newArr = array();
foreach($arr as $row){
foreach($row as $key=>$r){
if($key == 'socket_id' && $r==2)
$newArr[] = $row;
}
}
print_r($newArr);

$result = array();
foreach($input as $i){
if($i['SocketDecimal']==50)
$result[]=$i;
}

You can do it by this method
foreach ($yourarray as $key => $value){
$newarray = array("SocketDecimal"=>$value["SocketDecimal"];
}
print_r($newarray);

If your result array is like given below
$arr = array(
array( 'SocketID' => 1, 'SocketName' => 'Name', 'SocketDecimal' => 0, 'SocketHex' => 0, 'SocketAtt' => 1, 'Category' => 1, 'Value' => 100, 'Procentage' => 0 ),
array ( 'SocketID' => 2, 'SocketName' => 'Name2', 'SocketDecimal' => 50, 'SocketHex' => 32, 'SocketAtt' => 1, 'Category' => 1, 'Value' => 800, 'Procentage' => 0 ),
array ( 'SocketID' => 3, 'SocketName' => 'Name3', 'SocketDecimal' => 100, 'SocketHex' => 64, 'SocketAtt' => 1, 'Category' => 1, 'Value' => 60, 'Procentage' => 0 )
);
print_r($arr);
Get row for SocketDecimal=50 by following loop:
<pre>
$resultArr = '';
foreach($arr as $recordSet)
{
if($recordSet['SocketDecimal'] == 50)
{
$resultArr[] = $recordSet;
break;
}
}
</pre>
print_r($resultArr);
break foreach loop so that it will not traverse for all the array when SocketDecimal(50) founded.

You can use array_column + array_search combo
$array = Array (
"0" => Array ( "SocketID" => 1, "SocketName" => "Name", "SocketDecimal" => 0, "SocketHex" => 00, "SocketAtt" => 1, "Category" => 1, "Value" => 100, "Procentage" => 0 ) ,
"1" => Array ( "SocketID" => 2, "SocketName" => "Name2", "SocketDecimal" => 50, "SocketHex" => 32, "SocketAtt" => 1, "Category" => 1, "Value" => 800, "Procentage" => 0 ),
"2" => Array ( "SocketID" => 3, "SocketName" => "Name3", "SocketDecimal" => 100, "SocketHex" => 64, "SocketAtt" => 1, "Category" => 1, "Value" => 60 ,"Procentage" => 0 )
);
var_dump($array[array_search(50,array_column($array,'SocketDecimal'))]);

Related

multidimensional array php - sum values with same groupRange

I will try to explain my problem in small examples:
I have a multidimensional array that represents data from the database, lets's say the input looks like this:
Array
(
[0] => Array
(
[groupRange] => 20-25
[value] => 12
[followersFemaleRate] => 12
[followersMaleRate] => 14
)
[1] => Array
(
[groupRange] => 30-44
[value] => 32
[followersFemaleRate] => 17
[followersMaleRate] => 3
)
[2] => Array
(
[groupRange] => 30-44
[value] => 88
[followersFemaleRate] => 17
[followersMaleRate] => 3
)
)
What I want? To sum value, followersFemaleRate, followersMaleRate with the same groupRange, so the output should be this:
Array
(
[0] => Array
(
[groupRange] => 20-25
[value] => 12
[followersFemaleRate] => 12
[followersMaleRate] => 14
)
[1] => Array
(
[groupRange] => 30-44
[value] => 120
[followersFemaleRate] => 34
[followersMaleRate] => 6
)
)
My code:
$RangeArray = [];
foreach($dbProfile->getData() as $d) {
foreach ($d->getGroupPercentages() as $x){
$ageRangeSingleArray['groupRange'] = $x->getGroupRange();
$ageRangeSingleArray['value'] = $x->getValue();
$ageRangeSingleArray['followersFemaleRate'] = $x->getFollowerGenderFemale();
$ageRangeSingleArray['followersMaleRate'] = $x->getFollowerGenderMale();
$RangeArray [] = $ageRangeSingleArray;
}
}
However im stuck, my idea is to first check if groupRage already exists, if yes, sum values for that range, if not add new element groupRange with values, any help with code?
#Salines solution was good, but I offer a simple solution for the beginners...
Another simple solution to your problem:
$input = [
[
'groupRange' => '20-25',
'value' => 12,
'followersFemaleRate' => 12,
'followersMaleRate' => 14,
],
[
'groupRange' => '30-44',
'value' => 88,
'followersFemaleRate' => 17,
'followersMaleRate' => 3,
],
[
'groupRange' => '30-44',
'value' => 32,
'followersFemaleRate' => 17,
'followersMaleRate' => 3,
],
];
$groupRangeHolder = [];
$output = [];
foreach($input as $item) {
if( ! array_key_exists( $item['groupRange'] , $groupRangeHolder ) )
{
$groupRangeHolder[$item['groupRange']]['value'] = $item['value'];
$groupRangeHolder[$item['groupRange']]['followersFemaleRate'] = $item['followersFemaleRate'];
$groupRangeHolder[$item['groupRange']]['followersMaleRate'] = $item['followersMaleRate'];
}
else
{
$groupRangeHolder[$item['groupRange']]['value'] += $item['value'];
$groupRangeHolder[$item['groupRange']]['followersFemaleRate'] += $item['followersFemaleRate'];
$groupRangeHolder[$item['groupRange']]['followersMaleRate'] += $item['followersMaleRate'];
}
}
$cur = 0;
foreach($groupRangeHolder as $key => $values)
{
$output[$cur]['groupRange'] = $key;
$output[$cur]['value'] = $values['value'];
$output[$cur]['followersFemaleRate'] = $values['followersFemaleRate'];
$output[$cur++]['followersMaleRate'] = $values['followersMaleRate'];
}
echo "<pre>";
print_r($output);
echo "</pre>";
try:
$input = [
[
'groupRange' => '20-25',
'value' => 12,
'followersFemaleRate' => 12,
'followersMaleRate' => 14,
],
[
'groupRange' => '30-44',
'value' => 88,
'followersFemaleRate' => 17,
'followersMaleRate' => 3,
],
[
'groupRange' => '30-44',
'value' => 32,
'followersFemaleRate' => 17,
'followersMaleRate' => 3,
],
];
$groupedArray = [];
foreach( $input as $item ){
$groupedArray[$item['groupRange']]['groupRange'] = $item['groupRange'];
$groupedArray[$item['groupRange']]['value'] = ($groupedArray[$item['groupRange']]['value'] ?? 0) + $item['value'];
$groupedArray[$item['groupRange']]['followersFemaleRate'] = $item['followersFemaleRate'];
$groupedArray[$item['groupRange']]['followersMaleRate'] = $item['followersMaleRate'];
}
$output = array_values($groupedArray);
print_r($output);
output:
Array
(
[0] => Array
(
[groupRange] => 20-25
[value] => 12
[followersFemaleRate] => 12
[followersMaleRate] => 14
)
[1] => Array
(
[groupRange] => 30-44
[value] => 120
[followersFemaleRate] => 17
[followersMaleRate] => 3
)
)

Find the difference from a multi-dimencional array to a normal array in php

I have 2 arrays one contains just a list of email address and the other contains emails and names.
The list of emails in array1 are stored in a database and the other array is a list of new and current users.
I have tried using array_diff however this only seems to work if I specify in my loop that I just want emails.
$array1 = array(
0 => 'dave#daveshouse.com',
1 => 'sam#samshouse.com',
2 => 'jim#jimshouse.com',
3 => 'olly#ollyshouse.com',
4 => 'tom#tomshouse.com'
);
$array2 = array(
0 => array(
0 => 'tom',
1 => 'tom#tomshouse.com'
),
1 => array(
0 => 'james',
1 => 'james#jameshouse.com'
),
2 => array(
0 => 'marvin',
1 => 'marvin#marvinshouse.com'
),
3 => array(
0 => 'jane',
1 => 'jane#janeshouse.com'
),
);
$array2emails = array();
foreach ($array2 as $item) {
$array2emails[] = $item[1];
}
$result = array_diff($array2emails, $array1);
$results gives me
Array
(
[1] => james#jameshouse.com
[2] => marvin#marvinshouse.com
[3] => jane#janeshouse.com
)
however I need to get this:
Array
(
[1] => array(
[0] => james
[1] => james#jameshouse.com
)
[2] => array(
[0] => marvin
[1] => marvin#marvinshouse.com
)
[3] => array(
[0] => jane
[1] => jane#janeshouse.com
)
)
Any help would be much appreciated. Thanks
Since the array returned by array_diff has the same keys as the original array, you can use that to get the elements of the original array back, with array_intersect_key.
$array1 = array(
0 => 'dave#daveshouse.com',
1 => 'sam#samshouse.com',
2 => 'jim#jimshouse.com',
3 => 'olly#ollyshouse.com',
4 => 'tom#tomshouse.com'
);
$array2 = array(
0 => array(
0 => 'tom',
1 => 'tom#tomshouse.com'
),
1 => array(
0 => 'james',
1 => 'james#jameshouse.com'
),
2 => array(
0 => 'marvin',
1 => 'marvin#marvinshouse.com'
),
3 => array(
0 => 'jane',
1 => 'jane#janeshouse.com'
),
);
$array2emails = array_column($array2, 1);
$keys = array_diff($array2emails, $array1);
$result = array_intersect_key($array2, $keys);
print_r($result);
Result:
Array
(
[1] => Array
(
[0] => james
[1] => james#jameshouse.com
)
[2] => Array
(
[0] => marvin
[1] => marvin#marvinshouse.com
)
[3] => Array
(
[0] => jane
[1] => jane#janeshouse.com
)
)
$array1 = array(
0 => 'dave#daveshouse.com',
1 => 'sam#samshouse.com',
2 => 'jim#jimshouse.com',
3 => 'olly#ollyshouse.com',
4 => 'tom#tomshouse.com'
);
$array2 = array(
0 => array(
0 => 'tom',
1 => 'tom#tomshouse.com'
),
1 => array(
0 => 'james',
1 => 'james#jameshouse.com'
),
2 => array(
0 => 'marvin',
1 => 'marvin#marvinshouse.com'
),
3 => array(
0 => 'jane',
1 => 'jane#janeshouse.com'
),
);
$diffs = array();
foreach ($array2 as $item) {
if (!in_array($item[1], $array1)) {
$diffs[] = $item;
}
}
Since you are using a foreach loop why not create the array there?
As long as the arrays are not to long this will word nicely. I even took the original key into the new array. So you will be able to do other comparison methods to it.
$array1 = [
0 => 'dave#daveshouse.com',
1 => 'sam#samshouse.com',
2 => 'jim#jimshouse.com',
3 => 'olly#ollyshouse.com',
4 => 'tom#tomshouse.com'
];
$array2 = [
0 => [
0 => 'tom',
1 => 'tom#tomshouse.com'
],
1 => [
0 => 'james',
1 => 'james#jameshouse.com'
],
2 => [
0 => 'marvin',
1 => 'marvin#marvinshouse.com'
],
3 => [
0 => 'jane',
1 => 'jane#janeshouse.com'
],
];
$arrayExits = [];
foreach ($array2 as $key => $item) {
if(in_array($item[1], $array1)) {
$arrayExits[$key] = $item;
}
}
print_r($arrayExits);
Use array_filter function.
function filterEmail($value, $key){
global $array1;
return !in_array($value[1], $array1);
}
$emailDiff = array_filter($array2, 'filterEmail' , ARRAY_FILTER_USE_BOTH );
print_r($emailDiff );

php multidimensional array as radio buttons with ID and array value

I am php noob. I have searched Google very thoroughly past couple of days and can't figure that out.
I have multidimensional array I have to convert to radio buttons with unique ID and values, but I can't seem to do it.
The json array:
Array
(
[0] => Array
(
[0] => Array
(
[available] => 1
[courier] => 1
[type] => 1
[price] => 42.89
[transitDays] => 3
)
[1] => Array
(
[available] => 1
[courier] => 1
[type] => 3
[price] => 50.50
[transitDays] => 4
)
[2] => Array
(
[available] => 0
)
...
)
[1] => Array
(
[0] => Array
(
[available] => 1
[courier] => 2
[type] => 1
[price] => 111
[transitDays] => 11
)
[1] => Array
(
[available] => 0
[courier] => 2
[type] => 4
[price] => 22
[transitDays] => 22
)
...
)
)
I need to make every output some of the values of every ['available']==1 array into radio buttons and on select be able to retrieve the data after form submission.
<p class="row"><input type="radio" id="option-<?php echo $i ?> value="service-<?php echo $i ?>" name="type" "> <?php echo $service['type']; ?> will cost <?php echo $service['price']; ?> and take <?php echo $service['days']; ?></p>
I have tried flattening arrays and spew available results, but I can't assign unique ID's then.
I tried
foreach ($providers as $provider) {
$mergeProvider = array_merge($provider);
foreach ($provider as $services){
$service = array_merge($services);
if( $service['available'] == 0 ) { unset($service); }
$serviceCount = count($service);
else {
include('offer.php'); //where is input type="button"
}
but this does not allow me unique ID's.
If I do:
foreach ($providers as $provider) {
$mergeProvider = array_merge($provider);
foreach ($provider as $services){
$service = array_merge($services);
$serviceCount = count($services);
for( $i = 1; $i < $serviceCount; $i++ ) {
echo "<pre>";
echo $serviceCount . "</pre>";
it spews out $serviceCount amount of different options where same option has different ID within it.
What can I do?
As an answer to the question in your comment:
You mean how to map the service-10 back to the array?
You then you need a way to get the '10' from the string 'service-10'. But that can go wrong when the numbers become greater than 10. For example 110 (1 and 10).
So I've added another example of how to could do this. I've updated the code with a pipe to separate the $key and the $subkey:
$uniqueKey = $key . '|' . $subKey;
I've also added a var_dump so you can see the mapped data that it matches.
// for example, this is your index.php
<html>
<head></head>
<body>
<form id="theForm" name="theForm" method="POST" action="submit.php">
<?php
$items = array(
0 => array(
0 => array(
"available" => 1,
"courier" => 1,
"type" => 1,
"price" => 42.89,
"transitDays" => 3
),
1 => array(
"available" => 1,
"courier" => 1,
"type" => 3,
"price" => 50.50,
"transitDays" => 4
),
),
1 => array(
0 => array(
"available" => 1,
"courier" => 2,
"type" => 1,
"price" => 111,
"transitDays" => 11
),
1 => array(
"available" => 0,
"courier" => 2,
"type" => 4,
"price" => 22,
"transitDays" => 22
),
)
);
foreach($items as $key => $item) {
foreach($item as $subKey => $subItem) {
if ($subItem["available"] === 1) {
$uniqueKey = $key . '|' . $subKey;
echo sprintf(
'<p class="row"><input type="radio" id="option-%1$s" value="service-%1$s" name="type">%2$s will cost %3$s and take %4$s</p>',
$uniqueKey,
$subItem["type"],
$subItem["price"],
$subItem["transitDays"]
);
}
}
}
?>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
For example this is your submit.php
<?php
$items = array(
0 => array(
0 => array(
"available" => 1,
"courier" => 1,
"type" => 1,
"price" => 42.89,
"transitDays" => 3
),
1 => array(
"available" => 1,
"courier" => 1,
"type" => 3,
"price" => 50.50,
"transitDays" => 4
),
),
1 => array(
0 => array(
"available" => 1,
"courier" => 2,
"type" => 1,
"price" => 111,
"transitDays" => 11
),
1 => array(
"available" => 0,
"courier" => 2,
"type" => 4,
"price" => 22,
"transitDays" => 22
),
)
);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['type'])) {
$type = $_POST['type'];
$positionDash = strpos($type, '-');
$positionPipe = strpos($type, '|');
if (false !== $positionDash && false !== $positionPipe) {
$tail = substr($type, $positionDash+1);
$tree = explode('|', $tail);
$mappedData = $items[$tree[0]][$tree[1]];
var_dump($mappedData);
}
}
}
Maybe you can create a unique key based on the keys of the foreach loops.
Then when you post the form, the name field will contain a unique value like service-00, service-01, service-10
For example:
$items = array(
0 => array(
0 => array(
"available" => 1,
"courier" => 1,
"type" => 1,
"price" => 42.89,
"transitDays" => 3
),
1 => array(
"available" => 1,
"courier" => 1,
"type" => 3,
"price" => 50.50,
"transitDays" => 4
),
),
1 => array(
0 => array(
"available" => 1,
"courier" => 2,
"type" => 1,
"price" => 111,
"transitDays" => 11
),
1 => array(
"available" => 0,
"courier" => 2,
"type" => 4,
"price" => 22,
"transitDays" => 22
),
)
);
// then loop through the $items and create unique key
foreach($items as $key => $item) {
foreach($item as $subKey => $subItem) {
if ($subItem["available"] === 1) {
$uniqueKey = $key . $subKey;
echo sprintf(
'<p class="row"><input type="radio" id="option-%1$s" value="service-%1$s" name="type">%2$s will cost %3$s and take %4$s</p>',
$uniqueKey,
$subItem["type"],
$subItem["price"],
$subItem["transitDays"]
);
}
}
}

Remove element from array in php

I am new to php and i want to remove element from array Here is my array:
Array
(
[Total] => 21600000
[Items] => Array
(
[2-13] => Array
(
[Item] => 2
[PID] => 13
[UPrice] => 11000000
[Qty] => 1
[Total] => 11000000
)
[58-167] => Array
(
[Item] => 58
[PID] => 167
[UPrice] => 5300000
[Qty] => 1
[Total] => 5300000
)
)
)
And i want to remove array element by PID.
I have try this but no luck:-
$ShoppingBag =$_SESSION['ssss'];
if ($ShoppingBag !== null && $ShoppingBag['Total'] > 0) {
foreach ($ShoppingBag['Items'] as $IOrder) {
if($IOrder["PID"]==13)
{
unset($ShoppingBag[$IOrder]);
}else
{
}
}
}
Please help. Thanks
You can try with one simple array map :)
$arr = [
'Total' => 21600000,
'Items' => [
'2-13' => [
'Item' => 2,
'PID' => 13,
'UPrice' => 11000000,
'Qty' => 1,
'Total' => 11000000
],
'58-167'=> [
'Item' => 58,
'PID' => 167,
'UPrice' => 5300000,
'Qty' => 1,
'Total' => 5300000
]
]
];
$test = array_map(function($ar) {
foreach($ar as $k=>$i) {
if( isset($i['PID']) && $i['PID'] == '13')
unset($ar[$k]);
}
return $ar; } , $arr);
var_dump($test);
You need 2 loop to do the action you want.
foreach($my_array as $key=>$value)
{
if(is_array($value))
{
foreach($value as $k=>$v)
{
if($k == 'PID')
{
unset($value[$k]);
}
}
}
}
with this you can remove only element with key PID.
Hi youre unsetting the $IOrder instead of the Item that you want to delete:
This code is a solution an i tested it :
$ShoppingBag = Array
(
"Total" => 21600000,
"Items" => Array
(
"2-13" => Array
(
"Item" => 2,
"PID" => 13,
"UPrice" => 11000000,
"Qty" => 1,
"Total" => 11000000,
),
"58-167" => Array
(
"Item" => 58,
"PID" => 167,
"UPrice" => 5300000,
"Qty" => 1,
"Total" => 5300000,
),
),
);
foreach($ShoppingBag["Items"] as $key => $value){
if($value["PID"]==13){
unset($ShoppingBag["Items"][$key]);
}
}
You should know that always when you're using foreach loop the foreach( $a as $b ) when you do something to $b , $a remains the same because tey are different variables :)
Hope it will help you .
Regards.
$arr = [
'Total' => 21600000,
'Items' => [
'2-13' => [
'Item' => 2,
'PID' => 13,
'UPrice' => 11000000,
'Qty' => 1,
'Total' => 11000000
],
'58-167'=> [
'Item' => 58,
'PID' => 167,
'UPrice' => 5300000,
'Qty' => 1,
'Total' => 5300000
]
]
];
$pid_to_remove = 13;
$new_ar = array_filter(
$arr,
function ($v) using ($pid_to_remove) {
return (!isset($v['PID'])) || ($v['PID'] != $pid_to_remove);
}
);

Join 2 multidimensional array

$items = array(
array(
'id' => 0,
'name' => 'Simple Sword',
'type' => 'weapon',
'price' => 200,
'value1' => 5,
'value2' => 10,
'value3' => 0,
'value4' => 0,
'value5' => 0
),
array(
'id' => 1,
'name' => 'Iron Sword',
'type' => 'weapon',
'price' => 500,
'value1' => 0,
'value2' => 0,
'value3' => 0,
'value4' => 0,
'value5' => 0
)
);
$inventory = array(
array(
'item' => 0,
'slot' => 1,
'value1' => 0,
'value2' => 0,
'value3' => 0,
'value4' => 0,
'value5' => 0,
'equipped' => 0
),
array(
'item' => 1,
'slot' => 2,
'value1' => 0,
'value2' => 0,
'value3' => 0,
'value4' => 0,
'value5' => 0,
'equipped' => 1
)
);
What I need is to join these 2 multidimensional arrays, or take the values, keys etc from the "Items" array and put it in the Inventory array where the "item" id matches the id from the Items array. Similiar to a INNER JOIN statement in SQL. How? I can't figure it out.
Secondly, I am trying to print out the $inventory array, I tried the following, but It didn't work:
foreach ($inventory as $a) {
foreach ($a as $b) {
echo $b['item'];
}
}
It gives me no output.
a little help with your second problem:
foreach ($inventory as $a => $b) {
echo $b['item'];
}
}
As for first question Zulkhaery Basrul gave good answer. I would also consider putting break statement if relation is one-to-one:
if($val['item'] == $items[$key]['id']) {
$newarr[] = array_merge($items[$key],$val);
break;
}
As for second question:
foreach ($inventory as $invKey => $aInventoryItem) {
echo $aInventoryItem['item'] . "\n";
}
I think you can just do this in order to echo the item from inventory:
foreach($inventory as $inv) {
echo $inv['item'];
}
foreach($inventory as $key=>$val)
{
if($val['item'] == $items[$key]['id'])
{
$newarr[] = array_merge($items[$key],$val);
}
}
check $newarr[] using print_r($newarr), here the output :
Array
(
[0] => Array
(
[id] => 0
[name] => Simple Sword
[type] => weapon
[price] => 200
[value1] => 0
[value2] => 0
[value3] => 0
[value4] => 0
[value5] => 0
[item] => 0
[slot] => 1
[equipped] => 0
)
[1] => Array
(
[id] => 1
[name] => Iron Sword
[type] => weapon
[price] => 500
[value1] => 0
[value2] => 0
[value3] => 0
[value4] => 0
[value5] => 0
[item] => 1
[slot] => 2
[equipped] => 1
)
)
Second question, to print out the $inventory array:
foreach ($inventory as $a)
{
echo $a['item'];
echo $a['slot'];
echo $a['value1'];
//...etc
}
I believe this function is what you're looking for:
// Join Arrays on Keys
function array_join($original, $merge, $on) {
if (!is_array($on)) $on = array($on);
foreach ($merge as $right) {
foreach ($original as $index => $left) {
foreach ($on as $from_key => $to_key) {
if (!isset($original[$index][$from_key])
|| !isset($right[$to_key])
|| $original[$index][$from_key] != $right[$to_key])
continue 2;
}
$original[$index] = array_merge($left, $right);
}
}
return $original;
}
Usage for your scenario:
print_r(array_join($items, $inventory, array('id' => 'item')));
I've asked the community for help with optimizing the LEFT JOIN version of the function here (the only differences are $remove unset and array_merge): How can I optimize my array_join (simulates a LEFT JOIN) function?

Categories