我有一个带有stdClass对象的数组,如下所示。我如何计算Interviewee_Name下的数量?
尝试计数,因为我会做一个数组,但得到一个错误,我不能因为stdClass对象,然后不确定如何从那里继续
Array
(
[0] => stdClass Object
(
[Interviewee_Name] => Array
(
[0] => stdClass Object
(
[id] => rn_Interviewee_Name_DIR_27
[value] => Janusz Jasinski
)
)
)
答案 0 :(得分:3)
这将获得from lib import window, widgets
from PyQt5.QtCore import pyqtSlot
class FileUploader:
def __init__ (self, windowObj):
self.progressBar = None
self.logViewer = None
self.closeButton = None
self.filePercent = 100
self.totalPercent = 0
self.fileSelectDialog = None
self.__createWidgets (windowObj)
return
def __createWidgets (self, windowObj):
vboxObj = widgets.VBox ()
hboxObj = widgets.HBox ()
self.progressBar = widgets.ProgressBar (parent=windowObj)
self.logViewer = widgets.TextEdit (parent=windowObj)
self.closeButton = widgets.PushButton ('&Close', parent=windowObj)
hboxObj.addWidget (self.progressBar)
hboxObj.addWidget (self.closeButton)
vboxObj.insertLayout (0, hboxObj)
vboxObj.addWidget (self.logViewer)
windowObj.setLayout (vboxObj)
(self.closeButton).clicked.connect (self.test)
return
def acceptInputFiles (self, winTitle, fileFilters, windowObj):
(self.progressBar).setRange (0,100)
(self.progressBar).setValue (0)
self.fileSelectDialog = window.FileDialog (title=winTitle, filter=fileFilters, parent=windowObj)
selectedFiles = (self.fileSelectDialog).getSelectedFiles ()
if len(selectedFiles) == 0:
(self.logViewer).append ('No Files to process')
return selectedFiles
@pyqtSlot()
def test (self):
print ('clicked')
下的元素数量,但它会计算所有元素,而不仅仅是对象。
Interviewee_Name
但是,如果您真的只想在count($arr[0]->Interviewee_Name)
中获取对象,则需要array_filter
数组才能获取对象,然后算新阵列:
Interviewee_Name
从数组中获取元素的语法类似于count(array_filter($arr[0]->Interviewee_Name, function ($el) {
return (gettype($el) == 'object');
}));
,但在这种情况下,$arr['index']
是对象的属性,因此您需要使用对象语法:Interviewee_Name
< / p>
答案 1 :(得分:1)
$array = json_decode(json_encode($formData), True);
我在计算之前添加了它,然后才有效!