2017 © Pedro Peláez
 

library arrayunit

both array and object can mix coding php together

image

feng/arrayunit

both array and object can mix coding php together

  • Wednesday, December 27, 2017
  • by zzbcraft
  • Repository
  • 0 Watchers
  • 0 Stars
  • 3 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

把数组转化成拥有数组特性的对象

composer require feng/arrayunit dev-master

案例代码, (*1)

require 'vendor/autoload.php';
 //数组转为对象[数组]集合类
 $arr = [
     'lesson'  => [
         'one' => 'english',
         'two' => 'chinese',
     ],
     'teacher' => [
         'one'   => 'zhang',
         'two'   => 'chen',
         'three' => 'huang',
     ],
 ];

 $std = new Feng\Arrayunit\Collection($arr);
 var_dump($std->lesson->one);
 var_dump($std->teacher->toArray());
 //新增属性赋值
 $std->lesson->three = 'math';
 var_dump($std->lesson->four);
 var_dump($std['lesson']);
 //混合对象和数组
 var_dump($std->lesson['one']);
 //测试循环
 foreach ($std as $item) {
     var_dump(count($item));
     var_dump($item->toArray());
     var_dump($item->one);
     var_dump($item->three);
 }

The Versions

27/12 2017

dev-master

9999999-dev

both array and object can mix coding php together

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by win7