jarvis Posted August 24, 2021 Share Posted August 24, 2021 Hi All, I hope I've used the right/correct term for this. So I'm using: array_map(addQuotes, $line) Which calls this function: function addQuotes($line) { return "\"$line\""; } It works and adds quotes around everything I need. However, I need to exclude one column called SKU. Is it possible to use the above but skip this column? I know using array_map means you need to return the same number of columns, so my thought was: function addQuotes($line) { if( $line['SKU']){ return $line; } else { return "\"$line\""; } } Therefore not applying the quote treatment. Sadly, didn't work (not surprised as figured it was too obvious! The data is an array: Array ( [0] => Array ( [0] => SKU [1] => Name [2] => Product Category [3] => ImageURL [4] => Manufacturer [5] => Model [6] => MPN [7] => EAN [8] => MemberID ) [1] => Array ( [SKU] => CIHYG21SX [Name] => Beko CIHYG21SX 60cm Gas Hob - Stainless Steel [Product Category] => Gas Hobs [ImageURL] => https://www.domain.com/uploads/2021/Beko-CIHYG21SX.png [Manufacturer] => Beko [Model] => CIHYG21SX [MPN] => CIHYG21SX [EAN] => 8690842386756 [MemberID] => 456789 ) [2] => Array ( [SKU] => T26DS49N0 [Name] => Neff T26DS49N0 60cm Gas Hob - Stainless Steel [Product Category] => Gas Hobs [ImageURL] => https://www.domain.com/uploads/2018/Neff-T26DS49N0.jpg [Manufacturer] => Neff [Model] => T26DS49N0 [MPN] => T26DS49N0 [EAN] => 4242004203384 [MemberID] => 456789 ) ) I'm then using a loop to get the data and pass into my function (if that helps) No doubt something I've overlooked but any help is much appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/313594-array_map-skip-column/ Share on other sites More sharing options...
jarvis Posted August 24, 2021 Author Share Posted August 24, 2021 This can be ignored. I found an alternative solution Apologies! Quote Link to comment https://forums.phpfreaks.com/topic/313594-array_map-skip-column/#findComment-1589319 Share on other sites More sharing options...
requinix Posted August 24, 2021 Share Posted August 24, 2021 array_map doesn't pass the array key. You could call it with two arrays (the first of values and second of keys) but that would reindex the array. array_walk with the value by-reference would work. As would a simple foreach loop. 1 Quote Link to comment https://forums.phpfreaks.com/topic/313594-array_map-skip-column/#findComment-1589329 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.