123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Mead
- * Date: 2019/1/23
- * Time: 9:11 AM
- */
- function php2js($arr)
- {
- return json_encode($arr, true);
- }
- function js2php($str)
- {
- return json_decode($str, true);
- }
- function arr2option($arr)
- {
- return collect($arr)->map(function ($key, $val) {
- return [
- 'label' => $key,
- 'value' => $val,
- 's_value' => (string)$val
- ];
- })->values();
- }
- function str2arr($str, $glue = ',')
- {
- return explode($glue, $str);
- }
- function arr2str($arr, $glue = ',')
- {
- return implode($glue, array_wrap($arr));
- }
- function category($key, $option = false)
- {
- if ($option) {
- return \Encore\Category\Models\Category::byKeyGetOptions($key);
- }
- return \Encore\Category\Models\Category::byId($key);
- }
|