2014-12-05 27 views
0

php函數array_slice或array_pop不工作?PHP array_slice OR array_pop not del?

object(stdClass)#2 (9) { 
    ["colVorname"]=> 
    string(3) "vor" 
    ["colNachname"]=> 
    string(4) "nach" 
    ["colGeb"]=> 
    string(10) "01.02.2014" 
    ["colStrasse"]=> 
    string(3) "str" 
    ["colPlz"]=> 
    string(3) "123" 
    ["colStadt"]=> 
    string(5) "stadt" 
    ["colEmail"]=> 
    string(9) "[email protected]" 
    ["colPasswort"]=> 
    string(4) "pass" 
    ["colPasswortw"]=> 
    string(4) "pass" 
} 

array_slice($submit, 0, -1) OR array_pop($submit)不是德爾colPasswortw爲什麼?:

+3

我t不是一個數組,首先。如果你從JSON中獲得它,使用'json_decode($ source_str,true)'將源代碼轉換爲關聯數組。就目前而言,你可以'取消設置'($ submit-> colPasswortw)'來移除該屬性。 – raina77ow 2014-12-05 09:43:59

+0

這個炒鍋,感謝:o) – Volk3r 2014-12-05 10:02:01

回答

1

objectarrayarray_slicearray_pop都是數組處理功能,所以你應該array轉換object,見下文

$submit = (array) $assoc_object; 

//and now you can use $submit with functions 

array_slice($submit, 0, -1) 
0

你正在處理php對象而不是數組,一個簡單的方法就是轉換它數組,然後應用功能,我的建議是

需要的功能:

json_encode

json_decode

示例:

<?php 
    $jsonedObject = json_encode($yourObject); 
    $resultantArray = json_decode($jsonedObject, TRUE); 
    print_r($resultantArray); 
?>