Technically, this is more of a general PHP question rather than a WordPress question which should be on Stack Overflow instead.
To echo
only the highest value from your array
, try storing your items ($s[1]
) into an array instead and then use max()
. Something like this:
$args = array(
'post_type' => array('product'),
'posts_per_page' => -1
);
$wcProductsArray = get_posts($args);
$skuList = array();
if (count($wcProductsArray)) {
foreach ($wcProductsArray as $productPost) {
$productSKU = get_post_meta($productPost->ID, '_sku', true);
$productTitle = get_the_title($productPost->ID);
if (strpos($productSKU, 'BUR') !== false) {
$s = explode("-",$productSKU);
// echo '<li>' . $s[1] . '</li>';
$skuList[] = $s[1];
}
}
}
echo( max($skuList) );
I don’t have a WooCommerce setup right now to validate it, so you’ll need to confirm that it works or play around with it.