There is no problem not worth solving, and no technology not worth learning!

In Laravel 6, when manipulating a multidimensional array, use reference pass to thin code implementation

1. The existing code is implemented as follows

<?php

use Illuminate\Support\Arr;

if (Arr::has($schema, 'sections')) {
    foreach ($schema['sections'] as $sectionKey => $section) {
        foreach ($section['blocks'] as $blockKey => $block) {
            if ($block['type'] == 'internal/size-chart/blocks/size-chart') {
                Arr::forget($schema, 'sections.' . $sectionKey . '.blocks.' . $blockKey);
                $blockOrderKey = array_search($blockKey, $section['block_order']);
                if ($blockOrderKey !== false) {
                    Arr::forget($schema, 'sections.' . $sectionKey . '.block_order.' . $blockOrderKey);
                }
            }
        }
        Arr::set($schema, 'sections.' . $sectionKey . '.block_order', array_values(Arr::get($schema, 'sections.' . $sectionKey . '.block_order')));
    }
}

return $schema;

2. Use reference pass to implement in thin code, you can put arr::forget($schema,sections.. $SectionKey ..blocks.. $blockkey); replace with: arr::forget($section,blocks.. $blockkey);

<?php
 
use Illuminate\Support\Arr;
 
if (Arr::has($schema, 'sections')) {
    foreach ($schema['sections'] as $sectionKey => &$section) {
        foreach ($section['blocks'] as $blockKey => $block) {
            if ($block['type'] == 'internal/size-chart/blocks/size-chart') {
                Arr::forget($section, 'blocks.' . $blockKey);
                $blockOrderKey = array_search($blockKey, $section['block_order']);
                if ($blockOrderKey !== false) {
                    Arr::forget($section, 'block_order.' . $blockOrderKey);
                }
            }
        }
        Arr::set($section, 'block_order', array_values(Arr::get($section, 'block_order')));
    }
}
 
return $schema;

PHP / Laravel / Yii2 Legacy Project Maintenance & Long-Term Technical Support

If your PHP / Laravel / Yii2 project is already in production but needs bug fixing, API troubleshooting, performance optimization, developer handover support, or long-term maintenance, feel free to contact me for remote technical support.

Ideal For:
✅ PHP legacy systems without active maintenance
✅ Laravel / Yii2 project bug fixes
✅ Admin panel feature iterations
✅ RESTful API troubleshooting
✅ MySQL / Redis / Nginx performance issues
✅ Long-term remote part-time maintenance

We can start with a small task:
✅ Production error troubleshooting
✅ API issue analysis
✅ Slow query and performance bottleneck diagnosis
✅ Initial code structure review
✅ Deployment environment and log inspection

If you would like to discuss your project, please contact me and mention: PHP Maintenance Consultation.

Contact Me:
Telegram: @shuijingwan
WeChat: 13980074657
Email: shuijingwanwq@gmail.com

评论

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.