最近2018中文字幕在日韩欧美国产成人片_国产日韩精品一区二区在线_在线观看成年美女黄网色视频_国产精品一区三区五区_国产精彩刺激乱对白_看黄色黄大色黄片免费_人人超碰自拍cao_国产高清av在线_亚洲精品电影av_日韩美女尤物视频网站

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
phpspl庫(kù)的使用

1.SPL 是什么?
SPL:standard php library php標(biāo)準(zhǔn)庫(kù),此 從php5.0起開(kāi)始內(nèi)置的組件和接口,在5.3以后逐漸成熟。因?yàn)閮?nèi)置在php5開(kāi)發(fā)環(huán)境中,無(wú)需任何配置。
根據(jù)官方定義,“a collection of interfaces and classes that are meant to solve standard problems.”
然而在目前的使用者,spl更多地被看做是一種使object模仿的array行為的interfaces和classes。
SPL對(duì)PHP引擎進(jìn)行了擴(kuò)展,例如ArrayAccess、Countable和SeekableIterator等接口,它們用于以數(shù)組形式操作對(duì)象。同時(shí)還可以使用RecursiveIterator,ArrayObjects等其他迭代器進(jìn)行數(shù)組的迭代操作。
他還內(nèi)置了幾個(gè)對(duì)象,例如Exceptions,SplObserver,spltorage以及splautoloadregister,splclasses,iteratorapply等的幫助函數(shù),用于重載對(duì)應(yīng)的功能。
2.Iterator
spl的核心概念是Iterator,這指一種設(shè)計(jì)模式(Design Pattern),"provide an object which traverses some aggregate structure,abstracting away assumptions about the implementation of that structure."
通俗的說(shuō),Iterator能夠使許多不同的數(shù)據(jù)結(jié)構(gòu),都能有統(tǒng)一的操作界面,比如一個(gè)數(shù)據(jù)庫(kù)的結(jié)果集、同一目錄的文件集或者一個(gè)文本中每一行構(gòu)成的集合。
SPL規(guī)定,所有部署了Iterator界面的class,都可以用在foreach loop中。Iterator界面包含以下必須部署的五個(gè)方法:

成都創(chuàng)新互聯(lián)長(zhǎng)期為1000多家客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開(kāi)放共贏平臺(tái),與合作伙伴共同營(yíng)造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為南寧企業(yè)提供專業(yè)的網(wǎng)站設(shè)計(jì)制作、成都網(wǎng)站設(shè)計(jì),南寧網(wǎng)站改版等技術(shù)服務(wù)。擁有10年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開(kāi)發(fā)。

  • current()

    This method returns the current index's value. You are solely
    responsible for tracking what the current index is as the
    interface does not do this for you.

    • key()

      This method returns the value of the current index's key. For
      foreach loops this is extremely important so that the key
      value can be populated.

    • next()

      This method moves the internal index forward one entry.

    • rewind()

      This method should reset the internal index to the first element.

    • valid()

      This method should return true or false if there is a current
      element. It is called after rewind() or next().

ArrayAccess界面
部署ArrayAccess界面,可以使object像Array那樣操作,但是必須包含四個(gè)必須部署的方法

  • offsetExists($offset)
    This method is used to tell php if there is a value
    for the key specified by offset. It should return
    true or false.
  • offsetGet($offset)
    This method is used to return the value specified
    by the key offset.
  • offsetSet($offset, $value)
    This method is used to set a value within the object,
    you can throw an exception from this function for a
    read-only collection.
  • offsetUnset($offset)
    This method is used when a value is removed from
    an array either through unset() or assigning the key
    a value of null. In the case of numerical arrays, this
    offset should not be deleted and the array should
    not be reindexed unless that is specifically the
    behavior you want.
    IteratorAggregate界面
    RecursiveIterator界面
    這個(gè)界面用于遍歷多層數(shù)據(jù),繼承了Iterator界面,因而也具有標(biāo)準(zhǔn)的current()/key()/next()和valid()方法。同時(shí)它自己還規(guī)定了getChildren()和hasChildren()方法。
    SeekableIterator界面
    SeekableIterator界面也是Iterator界面的延伸,除了Iterator的五個(gè)方法以外,還規(guī)定了seek()方法,參數(shù)是元素的位置,返回該元素。若該位置不存在,則拋出OutOfBoundsException。
    Countable界面
    這個(gè)界面規(guī)定了一個(gè)count()方法,返回結(jié)果集的數(shù)量
    3.SPL Classes
    spl內(nèi)置類(lèi)
    查看所有內(nèi)置類(lèi)
    foreach(spl_classes() as $key=>$val){
    echo $key."=>".$val.'
    ';
    }
    DirectoryIterator類(lèi)
    這個(gè)類(lèi)用來(lái)查看一個(gè)目錄中所有文件和子目錄
    foreach(new DirectoryIterator('./') as $Item)
    {
    echo $Item.'
    ';
    }
    catch(Exception $e)
    {
    echo 'No files Found!';
    }

ArrayObject類(lèi)
此類(lèi)將Array轉(zhuǎn)換為Object

ArrayIterator類(lèi)
這個(gè)類(lèi)實(shí)際上是對(duì)ArrayObject類(lèi)的補(bǔ)充,為后者提供遍歷功能。也支持offset類(lèi)方法和count()方法

RecursiveArrayIterator類(lèi)和RecursiveIteratorIterator類(lèi)
ArrayIterator類(lèi)和ArrayObject類(lèi),只支持遍歷一維數(shù)組,如果要遍歷多維數(shù)組,必須先用RecursiveIteratorIterator生成一個(gè)Iterator,然后再對(duì)這個(gè)Iterator使用RecursiveIteratorIterator
FilterIterator
FilterIterator類(lèi)可以對(duì)元素進(jìn)行過(guò)濾,只要在accept()方法中設(shè)置過(guò)濾條件就可以了。

SimpleXMLIterator類(lèi)
這個(gè)類(lèi)用來(lái)遍歷xml文件
CachingIterator類(lèi)
這個(gè)類(lèi)有一個(gè)hasNext()方法,用來(lái)判斷是否還有下一個(gè)元素
LimitIterator類(lèi)
這個(gè)類(lèi)用來(lái)限定返回結(jié)果集的數(shù)量和位置,必須提供offset和limit兩個(gè)參數(shù),與SQL命令中的limit語(yǔ)句類(lèi)似
SplFileObject類(lèi)
這個(gè)類(lèi)用來(lái)對(duì)文本文件進(jìn)行遍歷


本文名稱:phpspl庫(kù)的使用
本文網(wǎng)址:http://fisionsoft.com.cn/article/ieciip.html