How to set an Arrays internal pointer to a specific position? PHP/XML

前端 未结 8 1460
花落未央
花落未央 2020-12-01 01:16

Im trying to build a little site using XML instead of a database.

I would like to build a next and prev button which will work relative to the content I have displa

8条回答
  •  旧巷少年郎
    2020-12-01 01:54

    I use this code for set internal pointer with key of array.

    reset($List);
    while (key($List) !== $id && key($List) !== null) next($List);
    if(key($List) === null) end($List);
    

    After that you can use prev() or next().

    Update follow notice from @VaclavSir

提交回复
热议问题