Php 数组迭代次数太多?有没有减少的办法
我有一个方法,它接受一个数组,然后查看$myItem['details']['move\u to\u position']索引,看看元素应该移动到什么位置。之后,它将该特定元素从数组中取出,然后使用splice将其插入到$myItem['details']['move_to_position']位置。 我担心每个LOP太多,想知道是否有一些方法可以缩短它。Php 数组迭代次数太多?有没有减少的办法,php,algorithm,php-5.3,Php,Algorithm,Php 5.3,我有一个方法,它接受一个数组,然后查看$myItem['details']['move\u to\u position']索引,看看元素应该移动到什么位置。之后,它将该特定元素从数组中取出,然后使用splice将其插入到$myItem['details']['move_to_position']位置。 我担心每个LOP太多,想知道是否有一些方法可以缩短它。 谢谢为什么你不直接使用usort()呢?我会诚实地将position重命名为position,尽管我喜欢你总是犯同样的错误。复制粘贴一致性如
谢谢为什么你不直接使用usort()呢?我会诚实地将
position
重命名为position
,尽管我喜欢你总是犯同样的错误。复制粘贴一致性如何在这个标记上使用usort。有没有偶然的代码示例?谢谢
protected static function arrayShuffling($itemsArray)
{
$itemSwitching = array();Switching
$shItem= array();
foreach ($itemArray as $i => $myItem) {
if (!in_array($myItem->_id, $itemSwitching)) {
$itemSwitching[$i]['_id'] = $myItem->_id;
$itemSwitching[$i]['poistion'] = $myItem['details']['move_to_poistion'];
}
foreach ($itemSwitching as $t => $pinPrep) {
if ($event->_id == $pinPrep['_id']) {
$shuffeledItem[$itemSwitching[$t]['poistion']] = $myItem;
unset($itemArray[$i]);
}
}
}
foreach($shItem as $key=>$shffuledItem){
array_splice( $itemArray, $key, 0, array($shffuledItem));
}
}