bad case:

<?php

foreach($user_detail AS $val) {
if(!empty($val->portrait)) { //假设这个循环从来没有到达过
$portrait[] = $val->portrait;
}
}
#此时。$portrait为NULL,而不是Array。 //以下的结果一定是NULL。不论$image_ids是什么。
$image_ids = array_merge($image_ids, $portrait);

good case:

<?

php

$portrait = array(); //作声明
foreach($user_detail AS $val) {
if(!empty($val->portrait)) { //假设这个循环从来没有到达过
$portrait[] = $val->portrait;
}
} #此时,$portrait为Array,而不是NULL。 //以下函数的结果是正确的。
$image_ids = array_merge($image_ids, $portrait);

结论:PHP变量在使用前声明,即使PHP是弱类型。

版权声明:本文博主原创文章,博客,未经同意不得转载。

Case learning的更多相关文章

  1. 【Software Test】Basic Of ST

    文章目录 Learning Objective Introduction Software Applications Before Software Testing What is testing? ...

  2. 课程三(Structuring Machine Learning Projects),第二周(ML strategy(2)) —— 1.Machine learning Flight simulator:Autonomous driving (case study)

    [中文翻译] 为了帮助您练习机器学习的策略, 在本周我们将介绍另一个场景, 并询问您将如何行动.我们认为, 这个工作在一个机器学习项目的 "模拟器" 将给一个任务, 告诉你一个机器 ...

  3. 课程三(Structuring Machine Learning Projects),第一周(ML strategy(1)) —— 1.Machine learning Flight simulator:Bird recognition in the city of Peacetopia (case study)

    []To help you practice strategies for machine learning, the following exercise will present an in-de ...

  4. 吴恩达《深度学习》-课后测验-第三门课 结构化机器学习项目(Structuring Machine Learning Projects)-Week1 Bird recognition in the city of Peacetopia (case study)( 和平之城中的鸟类识别(案例研究))

    Week1 Bird recognition in the city of Peacetopia (case study)( 和平之城中的鸟类识别(案例研究)) 1.Problem Statement ...

  5. 课程四(Convolutional Neural Networks),第二 周(Deep convolutional models: case studies) —— 0.Learning Goals

    Learning Goals Understand multiple foundational papers of convolutional neural networks Analyze the ...

  6. learning scala Case Classses

    package com.aura.scala.day01 object caseClasses { def main(args: Array[String]): Unit = { // 注意在实例化案 ...

  7. To discount or not to discount in reinforcement learning: A case study comparing R learning and Q learning

    https://www.cs.cmu.edu/afs/cs/project/jair/pub/volume4/kaelbling96a-html/node26.html [平均-打折奖励] Schwa ...

  8. [python] a little deep learning case

    from numpy import exp, array, random, dot class NeuralNetwork(): def __init__(self): random.seed(1) ...

  9. Transformation-Based Error-Driven Learning and Natural Language Processing: A Case Study in Part-of-Speech Tagging

    http://delivery.acm.org/10.1145/220000/218367/p543-brill.pdf?ip=116.30.5.154&id=218367&acc=O ...

随机推荐

  1. 关于NSArray的几种排序:

    #利用数组的sortedArrayUsingComparator调用 NSComparator  当中NSComparator事实上就是一个返回NSComparisonResult的block. ty ...

  2. Linux pipe功能

    1. 功能说明 pipe(管道建设): 1) 头 #include<unistd.h> 2) 定义函数: int pipe(int filedes[2]); 3) 函数说明: pipe() ...

  3. opencv 训练自己的分类器汇总

    原地址:http://www.cnblogs.com/zengqs/archive/2009/02/12/1389208.html OpenCV训练分类器 OpenCV训练分类器 一.简介 目标检测方 ...

  4. 2015年十大热门Android开源新项目

    2015年十大热门Android开源新项目 2015 即将结束,又到了大家喜闻乐见的年终盘点时刻啦,今天给大家盘点一下 2015 年 Android 开发领域新出现的 10 大热门开源项目.数据来自于 ...

  5. Samba &amp; Nginx - Resource temporarily unavailable

    先说说本人的开发环境:Win7 + Editplus + VMware(Centos+Samba+Nginx).用Samba在Centos上把web文件夹(如www)共享,然后在Win7上訪问这个文件 ...

  6. 百度地图AP1

    百度地图API的用法 百度地图API演示样例 百度地图API学习总结 <1> <%@ Page Language="C#" Inherits="Syst ...

  7. Wix打包系列 (六)制作升级和补丁包

    原文:Wix打包系列 (六)制作升级和补丁包 前面我们已经知道怎么制作一个完整安装包了,但我们的软件往往不能一次性就满足客户的需要,当客户需要我们给软件进行升级的时候,我们应该怎么做呢? 在这之前,我 ...

  8. OSPF理论总结

    OSPF学习总结一.OSPF协议的报文类型: 1. Hello 报文:主要用来发现.建立和维护邻居关系. 2. DD报文:数据库的描述报文,主要用来两台路由器的数据库同步. 3. LSR报文:链路状态 ...

  9. Python的控制结构(转)

    首先我的工作第一语言是c/c++(面向对象子集).选择学习python一方面是因为看很多人都说python开发效率高,所以想验证一下:另一方面,Eric S. Raymond在文章:如何成为一名黑客 ...

  10. nutch搏斗之一

    nutch搏斗之一 问题描述: 在用nutch1.0做generate 包括5亿url的crawldb时,它默认按照64M分块,分成777个map task,在运行的后期出现 Could not fi ...