开发者

Array separating output data

one other question

$_SESSION['files'][] = $sid . '-' . $data['Id'] . '-reg'
$_SESSION['files'][] = $sid . '-' . $data['Id'] . '-nor'
...

the files session should look like this when echoed

317e2b5a2376dd19cb5fc431bced949a-56-reg

how do i take $_SESSION['files'][] and separate the data into these variable $sid, $id, $type using - and the separator... something like this.

$sid = "317e2b5a2376dd19cb5fc431bced949a";
$id = "56";
$type = "reg";

following codaddict below example something like this开发者_如何学运维 would be right correct?

for($i=0;$i<count($_SESSION['files']);$i++) {
list($sid,$id,$type) = explode('-',$_SESSION['files'][$i]);
...
}


You can use explode:

list($sid, $id, $type) = explode('-', $filename, 3);

Or sscanf:

sscanf($filename, '%s-%s-%s', $sid, $id, $type);


You can use explode function as:

list($sid,$id,$type) = explode('-',$_SESSION['files'][$index]);

Ideone link

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜