简体   繁体   English

PHP格式长变量和占位符

[英]PHP Format long variables and place holder

I am trying create an array of variables in different types. 我正在尝试创建不同类型的变量数组。

My aim is to create a .csv file to use with Canada Post Electronic Shipping Tools. 我的目标是创建一个.csv文件,以与加拿大邮政电子运输工具一起使用。 (code to create .csv file is not included here) (此处不包含用于创建.csv文件的代码)

I am using Canada Post's Electronic Shipping Guide's 2.2.4 Import Orders Items Records - Layout Type 5 document. 我正在使用《加拿大邮政电子运输指南》的2.2.4进口订单项目记录-布局类型5文档。

I have to create 52 elements array and keep some "integer", "boolean","currency", "long", and "place holder values" in the array. 我必须创建52个元素数组,并在数组中保留一些“整数”,“布尔值”,“货币”,“长”和“占位符值”。

My issues are. 我的问题是。

  1. How can I define long values? 如何定义值?
  2. What should I do to fill "place holder" values. 我应该怎么做才能填写“占位符”值。

This is an example of place holder requirement. 这是占位符要求的示例。

Field NO:32, Field:US Postal Box indicator Type: Placeholder Length: 1 Format Notes: “1” indicates that the field is blank. 字段号:32,字段:US Postal Box指示器类型:占位符长度:1格式注释:“ 1”表示该字段为空白。

Below is the code I use to create an array 下面是我用来创建数组的代码

<?php
$record_count_array = array();
//Create an integer value
$integer = 00;
$integer =  (integer)$integer ;
//Create a boolean value
$boolean = 1;
$boolean =  (boolean )$boolean  ;
//Fake long value -  Please lset me know your suggestions
$long    = 100000;
$string  = "string_value";
//Create a currency value
$currency = 10.00;
$currency = money_format('%i', $currency);
//Fake spaceholder value -  Please lset me know your suggestions
$placeholder = 2;
//Create a 52 item array
for($count = 0; $count< 52 ; $count++)
{
if($count == 0 || $count == 23 || $count == 47){
$record_count_array[] = $integer;
}
elseif($count == 18 || $count == 24 || $count == 25 || $count == 26) {
$record_count_array[] = $long;
}elseif($count == 27 || $count == 28 || $count == 29 || $count == 32
|| $count == 33 || $count == 34 || $count == 35 || $count == 36
|| $count == 37 || $count == 38 || $count == 39 || $count == 40
|| $count == 41 || $count == 44 || $count == 48 || $count == 49
|| $count == 50) {
$record_count_array[] = $boolean;
}elseif($count == 31 || $count == 42 || $count == 43) {
$record_count_array[] = $placeholder;
}elseif($count == 46) {
$record_count_array[] = $currency;
}
else{
$record_count_array[] = $string;
}
}
var_dump($record_count_array)."<br />";
?>

And this is the output I get (using var_dump()) 这是我得到的输出(使用var_dump())

array(52) 
{[0]=> int(0) [1]=> string(12) "string_value" 
[2]=> string(12) "string_value" [3]=> string(12) "string_value" 
[4]=> string(12) "string_value" [5]=> string(12) "string_value" 
[6]=> string(12) "string_value" [7]=> string(12) "string_value" 
[8]=> string(12) "string_value" [9]=> string(12) "string_value" 
[10]=> string(12) "string_value" [11]=> string(12) "string_value" 
[12]=> string(12) "string_value" [13]=> string(12) "string_value" 
[14]=> string(12) "string_value" [15]=> string(12) "string_value" 
[16]=> string(12) "string_value" [17]=> string(12) "string_value" 
[18]=> int(100000) [19]=> string(12) "string_value" 
[20]=> string(12) "string_value" [21]=> string(12) "string_value" 
[22]=> string(12) "string_value" [23]=> int(0) [24]=> int(100000) 
[25]=> int(100000) [26]=> int(100000) [27]=> bool(true) 
[28]=> bool(true) [29]=> bool(true) [30]=> string(12) "string_value" 
[31]=> int(2) [32]=> bool(true) [33]=> bool(true) 
[34]=> bool(true) [35]=> bool(true) [36]=> bool(true) 
[37]=> bool(true) [38]=> bool(true) [39]=> bool(true) 
[40]=> bool(true) [41]=> bool(true) [42]=> int(2) 
[43]=> int(2) [44]=> bool(true) 
[45]=> string(12) "string_value" [46]=> string(5) "10.00" 
[47]=> int(0) [48]=> bool(true) 
[49]=> bool(true) [50]=> bool(true) 
[51]=> string(12) "string_value" } 

Can somebody guide me to 有人可以指导我

  1. Format long variables correctly. 正确格式化长变量。
  2. Understand what is "place holder" variable do and how to format them? 了解什么是“占位符”变量以及如何格式化它们?

Thank you very much 非常感谢你

1-您可以将long视为整数,因为PHP没有long类型(AFAIK)2-对于占位符,我不知道我是否正确理解了问题,但建议您看一下sprintfhttp://se2.php.net/sprintf )格式化字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM