根据缩进排序数组

时间:2019-04-01 13:39:26

标签: php arrays sorting

我有PHP中的当前数组,该数组正在从MySQL数据库中提取(PDO全部获取);

context['actual_pagination'] = my_pagination(myList=page_row_ids, pk=pk)
actual_pagination, first_page, last_page, page_number = my_pagination(myList=page_row_ids, pk=pk)

我需要拿出一些代码将数组转换为此;

  _connect(BluetoothDevice d) async {
    device = d;
// Connect to device
    deviceConnection = _flutterBlue
        .connect(device, timeout: const Duration(seconds: 4))
        .listen(
      null,
      onDone: _disconnect,
    );

// Update the connection state immediately
    device.state.then((s) {
      setState(() {
        deviceState = s;
      });
    });

// Subscribe to connection changes
    deviceStateSubscription = device.onStateChanged().listen((s) {
      setState(() {
        deviceState = s;
      });
      if (s == BluetoothDeviceState.connected) {

        device.discoverServices().then((s) {

          services = s;

          for(BluetoothService service in services) {
            for(BluetoothCharacteristic c in service.characteristics) {
              if(c.uuid == new Guid("06d1e5e7-79ad-4a71-8faa-373789f7d93c")) {
                _writeCharacteristic(c);
              } else {
                print("Nope");
              }
            }
          }
          setState(() {
            services = s;
          });
        });
      }
    });
  }

缩进为2.3.1的数组元素变成缩进为2.3的元素的子元素,依此类推...我需要拿出一些代码来自动格式化此数组以使其符合我的需要。我整天都在与多维循环打架,但是没有运气。任何指导和协助将不胜感激。

2 个答案:

答案 0 :(得分:1)

我已经创建了符合您要求的代码段,看看吧。

Please visit this URL to authorize this application: https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=2633527702-gb8ch6367en489rg1jcl0vdn71fkmvck.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fyt-analytics.readonly&state=5JAwZmLVfUSAs2P4TrdYDBtSShH276&prompt=consent&access_type=offline
Enter the authorization code:

Demo

答案 1 :(得分:1)

我整理了这段代码,只要您的顶层始终是“ xx”(例如“ 1.0”而不是“ 1”)就可以使用,然后我使用您给定的数据select t.name, a.LName, a.FName, a.MI from NewRecruit a left join UserName t on (a.LName + ',' + a.FName) = (t.name = ( select (vl.lastname + vf.firstname) from UserName as t cross apply (values (left(t.name, charindex(', ', t.name)), stuff(t.name, 1, charindex(', ', t.name) + 1, ''))) vl(lastname, rest) cross apply (values (left(vl.rest, charindex(' ', vl.rest + ' ')))) vf(firstname) )) 对它进行了测试变量。希望这会有所帮助。

$values