אני לא הצלחתי הרבה להתעמק בנושא הזה.
אבל אציין דוגמא של משהו שאולי זה חלק מהכוונה של @yossiz
ואולי זה יפתח קצת את התאבון להבין טוב יותר את הנושא (גם אני לא יודע בזה הרבה)
$rows = self::find()
->where(['ProjectID' => \common\models\GetProjectID::getProjectID()])
->andWhere(['id' => $selection])
->andWhere(['is', 'PaymentDetails', new \yii\db\Expression('null')])->asArray()->all();
$rows2 = [];
foreach ($rows as $row){
if ($row['TotalToPaid'] > 0) {
if (isset($Students[$row['StudentId']])) {
$row['Bank'] = $Students[$row['StudentId']]['BankNumber'];
$row['Branch'] = $Students[$row['StudentId']]['BranchNumber'];
$row['AccountNumber'] = $Students[$row['StudentId']]['AccountNumber'];
$row['TeudatZehut'] = $Students[$row['StudentId']]['Identity'];
$row['ClientName'] = $Students[$row['StudentId']]['Family'] . ' ' . $Students[$row['StudentId']]['Name'];
}else{
$row['Bank'] = '';
$row['Branch'] = '';
$row['AccountNumber'] = '';
$row['TeudatZehut'] = '';
$row['ClientName'] = '';
}
$rows2[] = $row;
}
}
return $rows2;
במקרה זה, היה לי מערך שעלי היה להוסיף נתונים לאיברים, ולקבל מערך חדש הכולל את האיברים.
אם זה היה כמו ב JS למשל הייתי עושה זאת פשוט יותר:
$rows = self::find()
->where(['ProjectID' => \common\models\GetProjectID::getProjectID()])
->andWhere(['id' => $selection])
->andWhere(['is', 'PaymentDetails', new \yii\db\Expression('null')])->asArray()->all();
foreach ($rows as $row){
if ($row['TotalToPaid'] > 0) {
if (isset($Students[$row['StudentId']])) {
$row['Bank'] = $Students[$row['StudentId']]['BankNumber'];
$row['Branch'] = $Students[$row['StudentId']]['BranchNumber'];
$row['AccountNumber'] = $Students[$row['StudentId']]['AccountNumber'];
$row['TeudatZehut'] = $Students[$row['StudentId']]['Identity'];
$row['ClientName'] = $Students[$row['StudentId']]['Family'] . ' ' . $Students[$row['StudentId']]['Name'];
}else{
$row['Bank'] = '';
$row['Branch'] = '';
$row['AccountNumber'] = '';
$row['TeudatZehut'] = '';
$row['ClientName'] = '';
}
}
}
return $rows;
דהיינו כשעושים foreach, הוא לא מעביר לי את האיבר האמיתי המקורי, אלא איבר משוכפל, ששינוי בו אינו משנה כלום באיבר המקורי, ב JS לעומת זאת ניתן להעביר משתנים אפילו לפונקציות שהן משנות את האיבר המקורי.
דוגמא לזה, פונקציות שאני משתמש איתן המון
function setDescendantProp(obj, desc, value) {
var arr = desc.split('.');
while (arr.length > 1) {
obj = obj[arr.shift()];
}
return obj[arr[0]] = value;
}
var obj = {a: {b: {c: 0}}};
var propPath = getPropPath(); // returns e.g. "a.b.c"
var result = setDescendantProp(obj, propPath, 1); // obj.a.b.c will now be 1
מקור: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval
אציין, שאני התחלתי עם PHP, וכשנתקלתי בפונקציה הנ"ל setDescendantProp לקח לי המון זמן לעבוד איך עובד הפלא ההוא.