تابع ووکامرسی wc_list_pluck دریافت فیلد های مشخص از آرایه های چند بعدی

تابع ووکامرسی wc_list_pluck – دریافت فیلد های مشخص از آرایه های چند بعدی
Syntax – سینتکس
(array) wc_list_pluck( (array) $list, (int|string) $callback_or_field, (null) $index_key = null );
Parameters – پارامتر ها (3)
- 1- $list (array)
- 2- $callback_or_field (int|string)
- 3- $index_key (null)
Returns – مقادیر بازگشتی (array)
Array of values.
Usage – نحوه استفاده
if ( !function_exists( 'wc_list_pluck' ) ) { require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-core-functions.php'; } // List of objects or arrays $list = array(); // Callback method from the object to place instead of the entire object $callback_or_field = null; // Optional. Field from the object to use as keys for the new array. // Default null. $index_key = null; // NOTICE! Understand what this does before running. $result = wc_list_pluck($list, $callback_or_field, $index_key);
Defined – محل تعریف
/includes/wc-core-functions.php
function wc_list_pluck( $list, $callback_or_field, $index_key = null ) { // Use wp_list_pluck if this isn't a callback $first_el = current( $list ); if ( ! is_object( $first_el ) || ! is_callable( array( $first_el, $callback_or_field ) ) ) { return wp_list_pluck( $list, $callback_or_field, $index_key ); } if ( ! $index_key ) { /** * This is simple. Could at some point wrap array_column() * if we knew we had an array of arrays. */ foreach ( $list as $key => $value ) { $list[ $key ] = $value->{$callback_or_field}(); } return $list; } /** * When index_key is not set for a particular item, push the value * to the end of the stack. This is how array_column() behaves. */ $newlist = array(); foreach ( $list as $value ) { if ( isset( $value->$index_key ) ) { $newlist[ $value->$index_key ] = $value->{$callback_or_field}(); } else { $newlist[] = $value->{$callback_or_field}(); } } return $newlist; }
versions – نسخه ها
از نسخه : 3.0.0
نسخه فعلی : 3.0.6
دیگر نسخه ها : 3.0.6 , 3.0.5 , 3.0.4 , 3.0.3 , 3.0.2
ارسال نظر