Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从magento字段中的数组中删除值_Php_Arrays_Magento_Array Difference - Fatal编程技术网

Php 从magento字段中的数组中删除值

Php 从magento字段中的数组中删除值,php,arrays,magento,array-difference,Php,Arrays,Magento,Array Difference,我有一个magento自定义集合,集合中的每个项目在前端都有自己的登录页集合/视图/索引/id/12等,并在管理后端进行管理 我有一个控制器操作,允许用户跟踪每个项目,并将用户ID保存/添加到项目字段值 下面的字段/属性值示例 以下操作按预期工作。然而,试图让unfollow操作不起作用。代码如下 //Get field/attribute values ie 123,234,345,456, $FollowProfilesArray = array($model2->getFollow

我有一个magento自定义集合,集合中的每个项目在前端都有自己的登录页集合/视图/索引/id/12等,并在管理后端进行管理

我有一个控制器操作,允许用户跟踪每个项目,并将用户ID保存/添加到项目字段值

下面的字段/属性值示例

以下操作按预期工作。然而,试图让unfollow操作不起作用。代码如下

//Get field/attribute values ie 123,234,345,456, 
$FollowProfilesArray = array($model2->getFollowProfiles());

//$profileid will be current users id
//used to remove user id from array
$remove_from_array = array_diff($FollowProfilesArray,array($profile_id,));

foreach($remove_from_array as $key => $value){
$select .= ''.$value.',';
}
//saves all ids except the removed users id
$model->setFollowProfiles($select);
基本上由于某种原因,当使用数组$model2->getFollowProfiles时,不允许从字段中删除用户id,值将其保存为12323434456

但是

当我将数组设置为硬编码值ARRAY123434456时,它会工作并删除指定的id

数组$model2->getFollowProfiles在等于12323434456时不起作用的任何原因


我是否必须内爆,爆炸$model2->getFollowProfiles或其他东西…?

好的,解决了是的。代码如下

//Get field/attribute values ie 123,234,345,456, 
$FollowProfilesArray = array($model2->getFollowProfiles());

//$profileid will be current users id
//used to remove user id from array
$remove_from_array = array_diff($FollowProfilesArray,array($profile_id,));

foreach($remove_from_array as $key => $value){
$select .= ''.$value.',';
}
//saves all ids except the removed users id
$model->setFollowProfiles($select);
改变

改变


因此,现在调用unfollowAction时,指定的ID将从属性值中删除,但保留任何其他ID值。

将数组数据作为变量的代码板示例..似乎数组数据作为变量也不起作用..返回相同的值输出问题,即12323434456,,
$FollowProfilesArray = array($model2->getFollowProfiles()); 
//explode out the attribute value
$FollowProfilesArray = explode(",","".$model2->getFollowProfiles()."");
foreach($remove_from_array as $key => $value){
$select .= ''.$value.',';}
    //so if $value is NULL save no value id, stoppped the adding of , to the attribute value

    foreach($remove_from_array as $key => $value){
    if($value == NULL) {
    //$select .= ''.$value.',';
    }else{
    $select .= ''.$value.',';           
    }
    }