我在一个网站上工作,我想在其中从字符串中提取几个字段。我用来获取该字符串的代码是:
<?php
for ($i = 0; $i < count($data['item']->logistic_out); $i++) {
echo strtolower($data['item']->logistic_out[$i]->logistics_times);
}
?>
上面的回显代码正在打印以下字符串,logistics_times
:
a: 7: {
s: 3: "mon";a: 2: {
s: 5: "start";s: 5: "09:00";s: 3: "end";s: 5: "21:00";
}
s: 3: "tue";a: 2: {
s: 5: "start";s: 5: "09:00";s: 3: "end";s: 5: "21:00";
}
s: 3: "wed";a: 2: {
s: 5: "start";s: 5: "09:00";s: 3: "end";s: 5: "21:00";
}
s: 3: "thu";a: 2: {
s: 5: "start";s: 5: "09:00";s: 3: "end";s: 5: "21:00";
}
s: 3: "fri";a: 2: {
s: 5: "start";s: 5: "09:00";s: 3: "end";s: 5: "21:00";
}
s: 3: "sat";a: 2: {
s: 5: "start";s: 5: "09:00";s: 3: "end";s: 5: "21:00";
}
s: 3: "sun";a: 2: {
s: 5: "start";s: 5: "09:00";s: 3: "end";s: 5: "21:00";
}
}
问题陈述:
我想知道我应该在上面的php代码中进行哪些更改,以便它通过解析以上字符串来提取以下信息:
mon 09:00 21:00
tue 09:00 21:00
wed 09:00 21:00
thu 09:00 21:00
fri 09:00 21:00
sat 09:00 21:00
答案 0 :(得分:1)
使用Str_replace()从字符串中删除空格并使用unserialize()将数据转换为数组:
val conf = new SparkConf().setAppName("App10").setMaster("local[*]")
// .set("spark.executor.memory", "200g")
.set("spark.driver.memory", "12g")
.set("spark.executor.cores", "4")
.set("spark.driver.cores", "4")
// .set("spark.testing.memory", "2147480000")
.set("spark.sql.shuffle.partitions", "20000")
.set("spark.driver.maxResultSize", "500g")
.set("spark.memory.offHeap.enabled", "true")
.set("spark.memory.offHeap.size", "200g")