在php中操作数组
我有一个文件上传网站,它有一个通过url上传的选项,我试图做的是每当用户通过url上传时,我检查我的数据库,如果存在通过相同url上传的文件,它会直接显示下载url,而不是再次上传 发送到上传脚本的数据是数组形式,如:在php中操作数组,php,Php,我有一个文件上传网站,它有一个通过url上传的选项,我试图做的是每当用户通过url上传时,我检查我的数据库,如果存在通过相同url上传的文件,它会直接显示下载url,而不是再次上传 发送到上传脚本的数据是数组形式,如: Array ( [0] => http://i41.tinypic.com/3342r93.jpg [1] => http://i41.tinypic.com/28cfub7.jpg [2] => http://i41.tinypic.com/12dsa3
Array (
[0] => http://i41.tinypic.com/3342r93.jpg
[1] => http://i41.tinypic.com/28cfub7.jpg
[2] => http://i41.tinypic.com/12dsa32.jpg
)
用于输出结果的数组的形式如下:
Array
(
[0] => Array
(
[id] => 43
[name] => 3342r93.jpg
[size] => 362750
[descr] =>
[password] =>
[delete_id] => 75CE
[upload_id] => 75F45CAE1
)
[1] => Array
(
[id] => 44
[name] => 28cfub7.jpg
[size] => 105544
[descr] =>
[password] =>
[delete_id] => D392
[upload_id] => 6676FD881
)
[2] => Array
(
[id] => 45
[name] => 12dsa32.jpg
[size] => 49000
[descr] =>
[password] =>
[delete_id] => 54C9
[upload_id] => A58614C01
)
)
Array (
[0] => http://i41.tinypic.com/3342r93.jpg
// [1] was removed
[2] => http://i41.tinypic.com/12dsa32.jpg
)
现在我想知道的是,如果链接已经上传,我只需将其添加到输出数组中,但要按顺序维护它(如果添加的链接是数组中的第二个,那么输出结果也应该显示在第二个)
那么,应该使用什么函数从输入数组中删除匹配的URL,并使用一个函数将其添加到序号为的输出数组中呢
//已编辑
是的,unset会做这件事,但我想维持秩序:
例如,在取消设置阵列后,如下所示:
Array
(
[0] => Array
(
[id] => 43
[name] => 3342r93.jpg
[size] => 362750
[descr] =>
[password] =>
[delete_id] => 75CE
[upload_id] => 75F45CAE1
)
[1] => Array
(
[id] => 44
[name] => 28cfub7.jpg
[size] => 105544
[descr] =>
[password] =>
[delete_id] => D392
[upload_id] => 6676FD881
)
[2] => Array
(
[id] => 45
[name] => 12dsa32.jpg
[size] => 49000
[descr] =>
[password] =>
[delete_id] => 54C9
[upload_id] => A58614C01
)
)
Array (
[0] => http://i41.tinypic.com/3342r93.jpg
// [1] was removed
[2] => http://i41.tinypic.com/12dsa32.jpg
)
但是输出数组将是
Array
(
[0] => Array
(
[id] => 43
[name] => 3342r93.jpg
[size] => 362750
[descr] =>
[password] =>
[delete_id] => 75CE
[upload_id] => 75F45CAE1
)
// this will become [1], so how can i add another output[1] and shift other
// items after it to [2], [3] and so on...
[1] => Array
(
[id] => 45
[name] => 12dsa32.jpg
[size] => 49000
[descr] =>
[password] =>
[delete_id] => 54C9
[upload_id] => A58614C01
)
)
您可以通过执行以下操作将其添加到输出数组:
$OutArray[2] = $element;
其中,$element是另一个具有id、名称、大小(等)元素的数组
至于从阵列中删除:
unset($OutArray[2]);
您可能需要阅读。您可以通过执行以下操作将其添加到输出数组中:
$OutArray[2] = $element;
其中,$element是另一个具有id、名称、大小(等)元素的数组
至于从阵列中删除:
unset($OutArray[2]);
您可能需要读取。如果有索引数组,可以通过执行以下操作删除值:
unset ($array[2]);
如果要将项添加到数组中,请使用以下缩写(无需指定索引!):
所有文档都在上如果您有索引数组,可以通过执行以下操作删除值:
unset ($array[2]);
如果要将项添加到数组中,请使用以下缩写(无需指定索引!):
所有文档都在上,为什么不使用if语句和/或
文件\u exists()
查看文件是否在那里。若您已经有一个包含这些值的数组,那个么它就不会被再次上传 为什么不使用if语句和/或文件\u exists()
查看文件是否存在。若您已经有一个包含这些值的数组,那个么它就不会被再次上传 这个问题很模糊,在我链接的手册页面上,搜索“pepesantillan at gmail.com”(从2007年12月19日12:25开始)。在我链接到的手册页面上,搜索“gmail.com上的pepesantillan”(从2007年12月19日12:25开始)。你要找的就是这个数组插入函数。