0

I do have the following code, I need to use foreach instead of while and each! How can I do it?

This originally came from js composer plugin:

while ( $activity = each( $this->init_activity ) ) {
    list( $object, $method, $params ) = $activity[1];
    if ( $object === 'mapper' ) {
        switch ( $method ) {
            case 'map':
                WPBMap::map( $params['tag'], $params['attributes'] );
                break;
            case 'drop_param':
                WPBMap::dropParam( $params['name'], $params['attribute_name'] );
                break;
            case 'add_param':
                WPBMap::addParam( $params['name'], $params['attribute'] );
                break;
            case 'mutate_param':
                WPBMap::mutateParam( $params['name'], $params['attribute'] );
                break;
            case 'drop_all_shortcodes':
                WPBMap::dropAllShortcodes();
                break;
            case 'drop_shortcode':
                WPBMap::dropShortcode( $params['name'] );
                break;
            case 'modify':
                WPBMap::modify( $params['name'], $params['setting_name'], $params['value'] );
                break;
        }
    }
}
}
bad_coder
  • 11,289
  • 20
  • 44
  • 72

2 Answers2

0
foreach($this->init_activity as $index => $value) {

     echo $index;
     var_dump($value);

}

By the way, the each() is

This function has been DEPRECATED as of PHP 7.2.0. Relying on this function is highly discouraged.

from manual.

Hope this helps!

Raffobaffo
  • 2,806
  • 9
  • 22
0

Change this line:

while ( $activity = each( $this->init_activity ) ) {

To this:

foreach( $this->init_activity as $key => $activity) {
Purple Tentacle
  • 178
  • 2
  • 5