这是我的代码
$query = mysql_query("SELECT * FROM accommodation_vacancies WHERE accommodation_id = '$accom'");
$results = mysql_fetch_array($query);
if($query === FALSE) {
die(mysql_error());
} else {
print_r($results);
foreach ($results as $result) {
echo $result['start_date']; echo "<br/>";
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的输出

通过使用print_rcommant我可以看到变量$results正常工作,查询也正常工作,我想我在foreach循环上有错误.谢谢.
$pass = array();
foreach ($var as $index)
{
if($index['Data']['Show'] == false)
continue;
$pass[] = $index;
}
echo json_encode($pass);
Run Code Online (Sandbox Code Playgroud)
我需要知道如何以更简化和更快的速度获得相同的结果.
所以,我有一个简单的代码部分,我需要处理一个对象数组,并知道数组中availability.prop1的某个对象是否等于true并返回true它,或者如果等于false,则返回false.这是一个非常简单的案例,我知道,但由于某些原因,我无法弄清楚我的堕落在哪里......
我对输出的期望是什么isSomeProp1EqualToTrue = true,因为数组中的第二个对象data具有正值prop1(true)
const data = [
{prop1: false, {prop2: 'someValue'},
{prop1: true, {prop2: 'someValue'},
{prop1: false, {prop2: 'someValue'}
]
const isSomeProp1EqualToTrue = data.forEach(availability => {
if (availability.prop1 === true) {
return true
}
return false
})
// expected: isSomeProp1EqualToTrue = true (that's what I nedd)
// current: isSomeProp1EqualToTrue = undefined (wrong)
Run Code Online (Sandbox Code Playgroud) 最近的更新导致我的代码中出现严重的性能损失.通过使用剖析器,我发现损失是由使用Linq的一条线引起的.我做了一些测试,发现Linq慢得多foreach.
List<int> numbers = new List<int>();
for (int i = 0; i < 1000; ++i)
numbers.Add(i);
var stopWatch = new Stopwatch();
{
int total = 0;
for (int i = 0; i < 1000; ++i)
total += i;
}
stopWatch.Start();
for (int j = 0; j < 1000000; ++j)
{
int total = 0;
for (int i = 0; i < 1000; ++i)
total += i;
}
stopWatch.Stop();
Console.WriteLine("Benchmark run time: {0}", stopWatch.ElapsedMilliseconds);
{
int total = 0; …Run Code Online (Sandbox Code Playgroud) 请查看以下代码
using System.Collections.Generic;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
List<Employee> employeeCollection = new List<Employee>();
for (int i = 1; i < 10; i++) employeeCollection.Add(new Employee {
EmployeeID = i,
EmployeeName = string.Concat("Employee", i),
Email = string.Concat("Email", i) });
//loop thru every record
foreach (Employee e in employeeCollection)
{
SendEMail(e);
}
}
private static void SendEMail(Employee employee)
{
// do something
}
}
class Employee
{
public int EmployeeID { get; set; }
public string EmployeeName …Run Code Online (Sandbox Code Playgroud) foreach ×5
c# ×2
php ×2
javascript ×1
linq ×1
loops ×1
mysql ×1
optimization ×1
performance ×1