手动反转字符串不起作用

时间:2016-09-15 22:35:21

标签: php

我试图在不使用docuRefRecIdsPerJournalMap的情况下反转字符串。我认为这将是一项简单的任务:

<!DOCTYPE html>
<html>
<head>
	<meta charset=utf-8 />
	<title></title>
	<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>
<script>
  var customInterpolationApp = angular.module('calculator', []);

  customInterpolationApp.config(function($interpolateProvider) {
    $interpolateProvider.startSymbol('{[{');
    $interpolateProvider.endSymbol('}]}');
  });


  customInterpolationApp.controller('myCtrl', function($scope) {
  $scope.items = [{
      name: 'Misko',
      title: 'Angular creator'
    }, {
      name: 'Igor',
      title: 'Meetup master'
    }, {
      name: 'Vojta',
      title: 'All-around superhero'
    }

  ];
});
</script>
</head>
<body>
 

<div ng-app="calculator" ng-controller='myCtrl'>

	<label for="calculator">Number</label>
	<input type="number" class="form-control" id="calculator" ng-model="number" required>

	<div class="table-responsive">
        <table class="table table-bordered table-hover table-striped">
          	<tr>
                <th></th>
                <th>Lbs of Product Needed</th>
                <th>Gallons of Product Needed</th>
                <th>Nitrogen</th>
                <th>Phosphorus</th>
                <th>Potassium</th>
                <th>Sulfur</th>
                <th>Calcium</th>
          	</tr>
          	<tr>
                <td>Urea</td>
                <td>{[{ (+number) / .46 | number:2 }]}</td>
                <td></td>
                <td>{[{ (+number) * .46 | number:2 }]}</td>
                <td>0.00</td>
                <td>0.00</td>
                <td>0.00</td>
                <td>0.00</td>
          	</tr>
          	<tr>
                <td>Ammonium Sulfate</td>
                <td>{[{ (+number) / .21 | number:2 }]}</td>
                <td></td>
                <td>{[{ (+number) * .21 | number:2 }]}</td>
                <td>0.00</td>
                <td>0.00</td>
                <td>{[{ (+number) / .21 * .12 | number:2 }]}</td>
                <td>0.00</td>
          	</tr>
          	<tr>
                <td>Calcium Nitate</td>
                <td>{[{ (+number) / .155 | number:2 }]}</td>
                <td></td>
                <td>{[{ (+number) * .155 | number:2 }]}</td>
                <td>0.00</td>
                <td>0.00</td>
                <td>0.00</td>
                <td>{[{ (+number) / .155 * .17 | number:2 }]}</td>
          	</tr>
          	<tr>
                <td>UN32</td>
                <td>{[{ (+number) / .32 | number:2 }]}</td>
                <td>{[{ (+number) / .32 / 11.06 | number:2 }]}</td>
                <td>{[{ (+number) * .32 | number:2 }]}</td>
                <td>0.00</td>
                <td>0.00</td>
                <td>0.00</td>
                <td>0.00</td>
          	</tr>
          	<tr>
                <td>CAN 17</td>
                <td>{[{ (+number) / .17 | number:2 }]}</td>
                <td>{[{ (+number) / .17 / 12.2 | number:2 }]}</td>
                <td>{[{ (+number) * .17 | number:2 }]}</td>
                <td>0.00</td>
                <td>0.00</td>
                <td>0.00</td>
                <td>{[{ (+number) / .17 * .12 | number:2 }]}</td>
          	</tr>
          	<tr>
                <td>Aqua</td>
                <td>{[{ (+number) / .20 | number:2 }]}</td>
                <td>{[{ (+number) / .20 / 7.58 | number:2 }]}</td>
                <td>{[{ (+number) * .20 | number:2 }]}</td>
                <td>0.00</td>
                <td>0.00</td>
                <td>0.00</td>
                <td>0.00</td>
          	</tr>
        </table>
		</div>
	</div>

<div>

</body>
</html>

结果是strrev()。这是为什么?

当我这样做时:

$str = 'I am a string';
$rev = '';

for($i = 0, $len = strlen($str), $j = $len -1; $i < $len; $i++, $j--) {
    $rev += $str[$j];
}

echo $rev;

我得到:0

为什么第二个数组返回了所需的结果,但第一个数组返回了错误的结果$str = 'I am a string'; $rev = ''; for($i = 0, $len = strlen($str), $j = $len -1; $i < $len; $i++, $j--) { echo $str[$j]; }

2 个答案:

答案 0 :(得分:1)

您使用.进行连接,而不是+仅用于添加:

$rev .= $str[$j];

答案 1 :(得分:1)

在php中,如果你想将字符串连接到.运算符,那么你需要+=而不是.=而不是var $j10 = $.noConflict(true); $j10(document).ready(function() { var list = "Current Sites"; /* Fields within the List you want to utilize or display */ var fields = "<ViewFields>" + "<FieldRef Name='Title' />" + "<FieldRef Name='Link' />" + "</ViewFields>"; /* Query parameters for the data set you want to return, in CAML syntax */ var query = "<Query>" + "<OrderBy>" + "<FieldRef Name='Title' Ascending='TRUE' />" + "</OrderBy>" + "</Query>"; /* Method Call */ GetListItems(list, fields, query); }); function GetListItems(listName, listFields, listQuery) { $j10().SPServices({ operation: "GetListItems", listName: listName, CAMLViewFields: listFields, CAMLQuery: listQuery, completefunc: function(xData, Status) { $j10(xData.responseXML).SPFilterNode("z:row").each(function() { /* Any processing required for each row of data begins here... */ /* Get Field Data */ var name = ($j10(this).attr("ows_SiteName")); var url = ($j10(this).attr("ows_Url")); /* Process and Display Field Data */ $j10("#yourContainerID").append("<option value='" + url.substr(url.indexOf("#") + 1) + "'>" + name.substr(name.indexOf("#") + 1) + "</option>"); }); } }); }