承接 shavy/s-array 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

shavy/s-array

Composer 安装命令:

composer require shavy/s-array

包简介

A Super Array for PHP. Allows more method calls

README 文档

README

PHP Extended Array

Examples

You can use it to add item s to an array list like so.

$array=new SArray;//create object

$array->add("banana","bread"); //add to the array. Think of it like ['banana','bread']



You can use it to get to the objects using a forloop.

foreach($array as $a){
        echo $a->get($i)
    }    

If you want to get the index of an item you can use the get method and tyoe it in.

$array->get($i);

>If you like the dot syntax it is already there for you and you can use it as such. To set a value for something you can do this.

$array->kv("person.firstname","bill");//neat eh?
$array->kv("person.lastname","bob");
$array->kv("person.age",5);

>This will create an array that will look like this:

array(
    "person"=>array(
        "firstname"=>"bill",
        "lastname"=>'bob',
        "age"=>5
    )
);


>You can get the people back by using dot-syntax like this as well

$array('person.firstname');//returns bill
$array("person.age");//returns 5

//This isn't a typo, you don't need a method name. This will key it very nice and short. 



>What about if you want to store something like a file name with no dot syntax

$array("filename.ext"); 
// this will try to get array['filename']['ext']

//want you really want is 

$array("filename.ext",false)

>What about if you want to overwrite or add a new array or SArray.

//you can use
$array->overwrite(SArray $data) //only takes in a super array
$array->array_overwrite($data) //regular array
// You can tell it exactly what to do. There is no checking in these methods

If that is a little too complicated you can just use the replace method

$array->replace($data);
//Let the program figure it out. 
//it will check types

You have you standard toArray method. This will go all the way down and convert objects to array and other arrays as well.

You can also use insert to insert into the middle of an array

$array->insert($data) //you can insert an array for a multi dimension array
$array->insertBatch($data)// you can insert and array of items
/*


$array=SArray::_add("item1","item4");//you can use _ to create the object and add something to it right away
$array->insert(array("item2","item3"),1);

// This will make 
/*

    array(
        "item1",
        array(
            "item2",
            "item3"
        ),
        "item4"
    )
    but what you really want is 
*/
$array=SArray::_add("item1","item4");//you can use _ to create the object and add something to it right away
$array->insertBatch(array("item2","item3"),1);
/*

    array(
        "item1",
        "item2",
        "item3"
        "item4"
    )
    more like it
*/


To get part of an array you can use sub($start,$end). This will return a plain array

$array->sub($start,$end);
$array->sub_as_SArray($start,$end);//they are different methods will likely add shorter version in update

$array->length();// this is not calculated so safe to use in for loops

$array->dump();// var_dump for you  

$array->pretty_print();// print_r not it is not the same as print_r($array)

// pretty_print converts to array then prints

//same as

print_r($array->toArray());

统计信息

  • 总下载量: 16
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-02-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固