<?php $array1 = array ( "products" => array( "category" => array( array( "product_sku" => "1", "product_type" => "Type", "customer_contact_name" => "Contact Name", "customer_telephone" => "0000 000 000", "customer_email" => "email@email.com", "customer_postcode" => "PostCode", "additional_info" => array( "some information" => "some information" ), "full_price" => "50.00", "product_name" => "Product Name", "product_id" => "1", "customer_rating" => "0" ), array( "product_sku" => "2", "product_type" => "Type", "customer_contact_name" => "Contact Name", "customer_telephone" => "0000 000 000", "customer_email" => "email@email.com", "customer_postcode" => "PostCode", "additional_info" => array( "some information" => "some information" ), "full_price" => "100.00", "product_name" => "Product Name", "product_id" => "2", "customer_rating" => "0" ) ) ) ); $array2 = array ( array( "product_sku" => "1", "product_type" => "Type", "contact_name" => "Contact Name", "phone" => "0000 000 000", "full_price" => "0.00", "product_name" => "Product Name", "product_id" => "1", "rating" => "0" ), array( "product_sku" => "3", "product_type" => "Type", "contact_name" => "Contact Name", "phone" => "0000 000 000", "full_price" => "80.00", "product_name" => "Product Name", "product_id" => "3", "rating" => "0" ) ); $skuFullPrices = array_column( $array1['products']['category'], 'full_price', 'product_sku' ); $array2 = array_map( fn($row) => array_replace( $row, ['full_price' => $skuFullPrices[$row['product_sku']] ?? $row['full_price']] ), $array2 ); usort( $array2, fn($a, $b) => $a['full_price'] <=> $b['full_price'] ); var_export($array2);
You have javascript disabled. You will not be able to edit any code.